Golang Fuego - Web framework generating OpenAPI 3 spec from source code - Pluggable to existing Gin & Echo APIs
Golang Fuego - Web framework generating OpenAPI 3 spec from source code - Pluggable to existing Gin & Echo APIs
The framework for busy Go developers
Explore and contribute to our 2025 Roadmap!
Production-ready Go API framework generating OpenAPI documentation from code. Inspired by Nest, built for Go developers.
Also empowers templating with html/template, a-h/templ and maragudk/gomponents:
see the example running live.
Chi, Gin, Fiber and Echo are great frameworks. But since they were designed a long time ago, their current API does not allow them to deduce OpenAPI types from signatures, things that are now possible with generics. Fuego offers a lot of "modern Go based" features that make it easy to develop APIs and web applications.
net/http compatible (no lock-in): Fuego is built on top of net/http,
so you can use any http.Handler middleware or handler! Fuego also supports
log/slog, context and html/template.net/http, with grouping and
middleware supportgo-playground/validatorfuego.InTransform and fuego.OutTransform interfaces - also useful for
custom validationnet/http middleware
or use the provided middlewares.html/template - you can still also use your own template system like
templ or gomponentspackage main
import "github.com/go-fuego/fuego"
func main() {
s := fuego.NewServer()
fuego.Get(s, "/", func(c fuego.ContextNoBody) (string, error) {
return "Hello, World!", nil
})
s.Run()
}package main
import "github.com/go-fuego/fuego"
type MyInput struct {
Name string `json:"name" validate:"required"`
}
type MyOutput struct {
Message string `json:"message"`
}
func main() {
s := fuego.NewServer()
// Automatically generates OpenAPI documentation for this route
fuego.Post(s, "/user/{user}", myController)
s.Run()
}
func myController(c fuego.ContextWithBody[MyInput]) (*MyOutput, error) {
body, err := c.Body()
if err != nil {
return nil, err
}
return &MyOutput{Message: "Hello, " + body.Name}, nil
}type MyInput struct {
Name string `json:"name" validate:"required"`
}
// Will be called just before returning c.Body()
func (r *MyInput) InTransform(context.Context) error {
r.Name = strings.ToLower(r.Name)
if r.Name == "fuego" {
return errors.New("fuego is not a valid name for this input")
}
return nil
}…package main
import (
"net/http"
"github.com/go-fuego/fuego"
)
func main() {
s := fuego.NewServer()
// Standard net/http middleware
fuego.Use(s, func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Hello", "World")
next.ServeHTTP(w, r)
})
})
// Standard net/http handler with automatic OpenAPI route declaration
fuego.GetStd(s, "/std", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, World!"))
})
s.Run()
}Please see the /examples folder for more examples.
…curl http://localhost:8088/std
# Hello, World!
curl http://localhost:8088 -X POST -d '{"name": "Your Name"}' -H 'Content-Type: application/json'
# {"message":"HELLO, YOUR NAME","best":"Fuego!"}
curl http://localhost:8088 -X POST -d '{"name": "Fuego"}' -H 'Content-Type: application/json'
# {"error":"cannot transform request body: cannot transform request body: fuego is not a name"}https://github.com/go-fuego/fuego/assets/46993939/7438a71c-75a4-4e88-a584-71da6362c575
ViewsSee the contributing guide. Thanks to everyone who has contributed to this project! ❤️
Made with contrib.rocks
See the board.
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.
No open issues yet, or sync has not completed.