Scroll is a lightweight library for building Go HTTP services at Mailgun. It is built on top of mux and adds:
- Service Discovery
- Graceful Shutdown
- Configurable Logging
- Request Metrics
Scroll is a work in progress. Use at your own risk.
go get github.com/mailgun/scroll
Building an application with Scroll is simple. Here's a server that listens for GET or POST requests to http://0.0.0.0:8080/resources/{resourceID}
and echoes back the resource ID provided in the URL.
package main
import (
"fmt"
"net/http"
"github.com/mailgun/scroll"
"github.com/mailgun/scroll/registry"
)
func handler(w http.ResponseWriter, r *http.Request, params map[string]string) (interface{}, error) {
return scroll.Response{
"message": fmt.Sprintf("Resource ID: %v", params["resourceID"]),
}, nil
}
func main() {
// create an app
appConfig := scroll.AppConfig{
Name: "scrollexample",
ListenIP: "0.0.0.0",
ListenPort: 8080,
Registry: ®istry.NopRegistry{},
}
app := scroll.NewAppWithConfig(appConfig)
// register a handler
handlerSpec := scroll.Spec{
Methods: []string{"GET", "POST"},
Paths: []string{"/resources/{resourceID}"},
Handler: handler,
}
app.AddHandler(handlerSpec)
// start the app
app.Run()
}