Documentation ¶
Overview ¶
Package gorestful is a helper package to get a gorestful compatible handler/middleware from the standard net/http Middleware factory (from github.com/slok/go-prometheus-middleware).
Example (GorestfulMiddleware) ¶
GorestfulMiddleware shows how you would create a default middleware factory and use it to create a Gorestful compatible middleware.
package main import ( "log" "net/http" gorestful "github.com/emicklei/go-restful" "github.com/prometheus/client_golang/prometheus/promhttp" prommiddleware "github.com/slok/go-prometheus-middleware" promgorestful "github.com/slok/go-prometheus-middleware/gorestful" ) func main() { // Create our middleware factory with the default settings. mdlw := prommiddleware.NewDefault() // Create our gorestful instance. c := gorestful.NewContainer() // Add the middleware for all routes. c.Filter(promgorestful.Handler("", mdlw)) // Add our handler, ws := &gorestful.WebService{} ws.Route(ws.GET("/").To(func(_ *gorestful.Request, resp *gorestful.Response) { resp.WriteEntity("Hello world") })) c.Add(ws) // Serve metrics from the default prometheus registry. log.Printf("serving metrics at: %s", ":8081") go http.ListenAndServe(":8081", promhttp.Handler()) // Serve our handler. log.Printf("listening at: %s", ":8080") if err := http.ListenAndServe(":8080", c); err != nil { log.Panicf("error while serving: %s", err) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(handlerID string, m prommiddleware.Middleware) gorestful.FilterFunction
Handler returns a gorestful compatible middleware from a Middleware factory instance. The first handlerID argument is the same argument passed on Middleware.Handler method.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.