June 2017
Beginner
1091 pages
22h 9m
English
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 ...
Read now
Unlock full access