Go-web is a framework for micro web app development. Build web apps as microservices.
Go-web is a tiny HTTP web server library which leverages go-micro to create micro web services as first class citizens in a microservice world. It wraps go-micro to give you service discovery, heartbeating and the ability to create web apps as microservices.
- Service Discovery
- Heartbeating
- Custom Handlers
Go-web makes use of go-micro which means it needs service discovery
See the go-micro for install instructions
For a quick start use consul
# install
brew install consul
# run
consul agent -dev
service := web.NewService(
web.Name("example.com"),
)
service.HandleFunc("/foo", fooHandler)
if err := service.Init(); err != nil {
log.Fatal(err)
}
if err := service.Run(); err != nil {
log.Fatal(err)
}
You might have a preference for a HTTP handler, so use something else. This loses the ability to register endpoints in discovery but we'll fix that soon.
import "github.com/gorilla/mux"
r := mux.NewRouter()
r.HandleFunc("/", indexHandler)
r.HandleFunc("/objects/{object}", objectHandler)
service := web.NewService(
web.Handler(r)
)
Go-web includes a http.Client with a custom http.RoundTripper that uses service discovery
c := service.Client()
rsp, err := c.Get("http://example.com/foo")
This will lookup service discovery for the service example.com
and route to one of the available nodes.