The Go framework for busy API developers
The only Go framework generating OpenAPI documentation from code. Inspired by Nest, built for Go developers.
Chi, Gin, Fiber and Echo are great frameworks. But since they are designed a long time ago, they do not enjoy the possibilities that provide modern Go. Op provides a lot of helper functions and features that make it easy to develop APIs.
- OpenAPI: Op automatically generates OpenAPI documentation from code
net/http
compatibile: Op is built on top ofnet/http
, so you can use anynet/http
middleware or handler!- Routing: Op provides a simple and fast router based on Go 1.22
net/http
- Serialization/Deserialization: Op automatically serializes and deserializes JSON and XML based on user provided structs (or not, if you want to do it yourself)
- Validation: Op provides a simple and fast validator based on go-playground/validator
- Transformation: easily transform your data after deserialization
- Middlewares: easily add a custom
net/http
middleware, or use the built-in middlewares.
package main
import (
"net/http"
"github.com/op-go/op"
"github.com/rs/cors"
chiMiddleware "github.com/go-chi/chi/v5/middleware"
)
type Received struct {
Name string `json:"name" validate:"required"`
}
type MyResponse struct {
Message string `json:"message"`
BestFramework string `json:"best"`
}
func main() {
s := op.New()
op.UseStd(s, cors.Default().Handler)
op.UseStd(s, chiMiddleware.Compress(5, "text/html", "text/css"))
op.Post(s, "/", func(c op.Ctx[Received]) (MyResponse, error) {
data, err := c.Body()
if err != nil {
return MyResponse{}, err
}
return MyResponse{
Message: "Hello, " + data.Name,
BestFramework: "Op!",
}, nil
})
op.GetStd(s, "/std", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, World!"))
})
s.Run()
}
See the contributing guide
I know you might prefer to use net/http
directly, but if having a frame can convince my company to use Go instead of Node, I'm happy to use it.