Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions article-service/main.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)
}