The Go framework for busy API developers
The only Go framework generating OpenAPI documentation from code. The modern NestJS for Go. But also completely different.
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.
- Simple: Op is easy to learn and use
- OpenAPI: Automatically generates OpenAPI documentation
- Fast: Op is built for performance
- Compatible: Op is built on top of stdlib
- Flexible: Op is highly configurable
- Extensible: Op is designed to be extended
- Testable: Op is designed for testing
- Secure: Op is designed with security in mind
- Modern: Op is designed for modern Go
- Reliable: Op is designed for production
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 := c.Body()
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()
}- Routing: Op provides a simple and fast router based on
net/http - OpenAPI: Op automatically generates OpenAPI documentation from code
- Middleware: easily add a custom
net/httpmiddleware, or use the built-in middlewares - Serialization: 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
- Normalization: easily normalize your data after deserialization
See the contributing guide