HTTP Middleware
In a proper production environment you can integrate with different packages and HTTP routers. Gorilla MUX
A very basic middleware which timestamps the http request being handled could be written as:
func notaryMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Stamp & Notarize
_, err = sdk.stamp(ctx, sdk.message.FromHttpRequest(r))
if err != nil {
log.Println("could not stamp: %v", err)
}
// Call the next handler, which can be another middleware in the chain, or the final handler.
next.ServeHTTP(w, r)
})
}Middlewares can be added to a router using Router.Use():
r := mux.NewRouter()
r.HandleFunc("/", handler)
r.Use(notaryMiddleware)Last updated
Was this helpful?