An api micro framework for golang, which focuses on ease of use and extensibility.
This project is currently in progress and the SDK will change dramatically. Use with caution.
You can get up and running with butter in no time at all.
-
install butter using go get
go get github.com/hugorut/butter
-
add a routing file in your package which defines a
routes
variable
package main
import (
"github.com/hugorut/butter"
"github.com/hugorut/butter/auth"
)
var routes []butter.ApplicationRoute = []butter.ApplicationRoute{
{
Name: "Index",
Method: "GET",
URI: "/",
Func: Index,
Middleware: auth.Chain{},
},
}
- define a butter handler, in this case our
Index
function, the signature is as follows:
func Index(app *butter.App) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello World!")
w.WriteHeader(200)
})
}
- in your main function run the butter server with the specified routes
package main
import (
"butter"
)
func main() {
butter.Serve(routes)
}
- give yourself a pat on the back, you just implemented your first page for your API.
Butter uses environment variables to give you the power to customise your butter application.
Butter uses godotenv
to load environment variables from your .env
file at the root of your project so that you can compose your application at run time.
Want to switch out a filesystem, just configure the .env
file and swap out providers. Butter's interfaces remain consistent.
Butter comes with a set of components accessible via the App
. These are: