goatte is a lightweight HTTP library for building web services in Go.
It's built on top of Go’s standard library and is inspired by net/http, django, and chi.
Thanks for checking it out.
No extra dependencies — just Go.
100% compatible with net/http.
-
Easy to use and learn
-
Clean and simple routing
-
Built-in support for middleware
-
URL reversing (name your routes and look them up)
-
Serve static files easily
-
Organize routes with sub-routers
-
100% compatible with net/http
-
Clean and minimal API
-
Zero dependencies (only uses the Go standard library)
go get github.com/mochams/goatte@latestCreate a web server with middleware, and a parameterized route:
package main
import (
"fmt"
"log"
"net/http"
"github.com/mochams/goatte"
)
// Sample middleware that logs messages before and after the request is handled
var ExampleMiddleware = func(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Before handler (middleware)")
next.ServeHTTP(w, r)
fmt.Println("After handler (middleware)")
})
}
func main() {
middleware := []goatte.Middleware{ExampleMiddleware}
router := goatte.NewRouter("main", middleware...)
// Also fine
// router := goatte.NewRouter("main", ExampleMiddleware)
router.Get("/users/{name}/", "user-detail", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("..Handling request in handler...")
w.Write([]byte("Hello, " + r.PathValue("name")))
})
log.Println("Server listening on http://localhost:3000")
log.Fatal(http.ListenAndServe(":3000", router))
}Start the server
go run .In a new shell, call the endpoint:
curl -i http://localhost:3000/users/goatte/You should see this in the terminal running your server:
Before handler (middleware)
..Handling request in handler...
After handler (middleware)And this in the response:
HTTP/1.1 200 OK
...
Hello, goatte% Looking for more examples?
Check out the examples/ folder for more examples
Contributions are welcome!
If you have ideas, bug fixes, or improvements, feel free to open a pull request.
goatte is inspired by the simplicity of Go’s standard net/http, Chi’s routing, and the best ideas of Django framework.