An HTTP server in Go kit
The true value of Go kit becomes apparent when we create an HTTP server for our endpoints to hash and validate.
Create a new file called server_http.go
and add the following code:
package vault import ( "net/http" httptransport "github.com/go-kit/kit/transport/http" "golang.org/x/net/context" ) func NewHTTPServer(ctx context.Context, endpoints Endpoints) http.Handler { m := http.NewServeMux() m.Handle("/hash", httptransport.NewServer( ctx, endpoints.HashEndpoint, decodeHashRequest, encodeResponse, )) m.Handle("/validate", httptransport.NewServer( ctx, endpoints.ValidateEndpoint, decodeValidateRequest, encodeResponse, )) return m }
We are importing the github.com/go-kit/kit/transport/http
package and (since we're also importing ...
Get Go Programming Blueprints - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.