O'Reilly logo

Distributed Computing with Go by V.N. Nikhil Anurag

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

concierge/api/query.go

Query all the available Librarian instances to retrieve search query results, rank them in order, and then send back the results:

package api import ( "bytes" "encoding/json" "fmt" "io" "io/ioutil" "log" "net/http" "os" "sort" "github.com/last-ent/distributed-go/chapter8/goophr/concierge/common" ) var librarianEndpoints = map[string]string{} func init() { librarianEndpoints["a-m"] = os.Getenv("LIB_A_M") librarianEndpoints["n-z"] = os.Getenv("LIB_N_Z") librarianEndpoints["*"] = os.Getenv("LIB_OTHERS") } type docs struct { DocID string 'json:"doc_id"' Score int 'json:"doc_score"' } type queryResult struct { Count int 'json:"count"' Data []docs 'json:"data"' } func queryLibrarian(endpoint string, stBytes io.Reader, ch ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required