Documentation ¶
Overview ¶
Package goa contains middleware for monitoring Goa applications.
The provided middleware works in the same way as compass/http.
Example usage:
// Get hooks and resolver for the middleware. hooks := prom.NewHooks(nil) resolver := NewContextResolver() // Create the middleware. mw, err := NewMiddleware(hooks, resolver) if err != nil { panic(err) } // Use the middleware in a service. svc := goa.New("example") svc.Use(mw) svc.ListenAndServe(":8080")
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustNewMiddleware ¶
MustNewMiddleware is like NewMiddleware, except it panics where NewMiddleware would return an error.
Example ¶
package main import ( "net/http" "github.com/goadesign/goa" mgoa "github.com/zenreach/compass/goa" mhttp "github.com/zenreach/compass/http" ) func main() { // To keep this simply our hooks won't do anything. hooks := &NilHooks{} // Create a resolver to name our endpoint "hello". resolver := mhttp.ResolverFunc(func(*http.Request) string { return "hello" }) // Create the Goa service, assign our middleware, and run it. svc := goa.New("example") svc.Use(mgoa.MustNewMiddleware(hooks, resolver)) svc.ListenAndServe(":8080") } // NilHooks implements http.Hooks as a set of noops. type NilHooks struct{} func (*NilHooks) RequestHook(endpoint string, req *http.Request) {} func (*NilHooks) ResponseHook(endpoint string, req *http.Request, res *mhttp.Response) {}
Output:
func NewMiddleware ¶
NewMiddleware creates a Goa middleware which calls the provided hooks during the request cycle. This must be used as the net/http middleware produced by http.NewMiddleware is incompatible with Goa.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.