Closed tleyden closed 9 years ago
Raw notes from @steveyen:
The call you'll want to make is cbgt/rest/NewRESTRouter()...
https://github.com/couchbaselabs/cbgt/blob/master/rest/rest.go#L101
For example, in your app somewhere...
import "github.com/couchbaselabs/cbgt/rest"
router, _, err := rest.NewRESTRouter("0.0.0", mgr, "", "", nil, rest.AssetDir, rest.Asset)
Note, I didn't test the above for compilation / sanity.
Then hook that router up to http and invoke http's ListenAndServe()...
http.Handle("/", router)
http.ListenAndServe("0.0.0.0:" + portNumber, nil)
Read on in case the above doesn't work...
The gotchas that you might run into, I'd guess, are around static HTML/JS/CSS resources. So, if that convenience API doesn't work, then the next best place to look is at cbft's implementation (which has the upside of working), but which doesn't use the NewRESTRouter convenience function.
Here's where the important magic happens in cbft before the ListenAndServe()...
https://github.com/couchbaselabs/cbft/blob/master/cmd/cbft/main.go#L137
router, err := MainStart(cfg, uuid, tagsArr, flags.Container, flags.Weight, flags.Extra, flags.BindHttp, flags.DataDir, flags.StaticDir, flags.StaticETag, flags.Server, flags.Register, mr)
... http.Handle("/", router) ... err = http.ListenAndServe(flags.BindHttp, nil)
The MainStart() function basically creates a cbgt.Manager, here...
https://github.com/couchbaselabs/cbft/blob/master/cmd/cbft/main.go#L221
And then invokes cbft.NewRESTRouter(), which is different than cbgt/rest.NewRESTRouter(). But, you can probably just copy & paste cbft's snippets of code, where it's implemented in cbft here...
https://github.com/couchbaselabs/cbft/blob/master/rest.go#L73
The important part there is that cbft.NewRESTRouter() creates a new gorilla mux router, and then initializes with with routes from cbgt, via...
http://godoc.org/github.com/couchbaselabs/cbgt/rest#InitRESTRouter
Done and pushed to feature/distributed_index_autofailover.
To view the CBGT CFG, go to curl localhost:4985/_cbgt/api/cfg
The CBGT REST endpoints / UI will make understanding and debugging the system much faster.