Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sleuth implementation #2

Merged
merged 1 commit into from Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions article-service/main.go
Expand Up @@ -10,12 +10,13 @@ import (

"github.com/afshin/sleuth-example/types"
"github.com/gorilla/mux"
"github.com/ursiform/sleuth"
)

const commentsURL = "http://localhost:9871/comments/%s"
const commentsURL = "sleuth://comment-service/comments/%s"

var (
client = new(http.Client)
client *sleuth.Client
data = make(map[string]*types.Article) // Key is article GUID.
)

Expand Down Expand Up @@ -83,6 +84,12 @@ func handler(res http.ResponseWriter, req *http.Request) {
func main() {
router := mux.NewRouter()
router.HandleFunc("/articles/{guid}", handler).Methods("GET")

// In the real world, the Interface field of the sleuth.Config object
// should be set so that all services are on the same subnet.
client, _ = sleuth.New(&sleuth.Config{})
client.WaitFor("comment-service")

fmt.Println("ready...")
http.ListenAndServe(":9872", router)
}
12 changes: 11 additions & 1 deletion comment-service/main.go
Expand Up @@ -9,9 +9,13 @@ import (

"github.com/afshin/sleuth-example/types"
"github.com/gorilla/mux"
"github.com/ursiform/sleuth"
)

var data = make(map[string][]*types.Comment) // Key is article GUID.
var (
client *sleuth.Client
data = make(map[string][]*types.Comment) // Key is article GUID.
)

func init() {
var err error
Expand Down Expand Up @@ -49,6 +53,12 @@ func handler(res http.ResponseWriter, req *http.Request) {
func main() {
router := mux.NewRouter()
router.HandleFunc("/comments/{guid}", handler).Methods("GET")

// In the real world, the Interface field of the sleuth.Config object
// should be set so that all services are on the same subnet.
config := &sleuth.Config{Service: "comment-service", Handler: router}
client, _ = sleuth.New(config)

fmt.Println("ready...")
http.ListenAndServe(":9871", router)
}