Skip to content

nhAnik/op

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ren'Py Graphviz

Op! ⏱️

Go Reference Go Report Card

The Go framework for busy API developers

The only Go framework generating OpenAPI documentation from code. Inspired by Nest, built for Go developers.

Why op?

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.

Features

  • OpenAPI: Op automatically generates OpenAPI documentation from code
  • net/http compatibile: Op is built on top of net/http, so you can use any net/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.

Examples

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()
}

Contributing

See the contributing guide

Disclaimer for experienced gophers

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.

License

GPL

About

A Go framework generating OpenAPI schema

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.4%
  • Makefile 1.6%