Thanks to visit codestin.com
Credit goes to github.com

Skip to content

hugoleborso/op

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 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. The modern NestJS for Go. But also completely different.

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.

  • 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

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

Features

  • 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/http middleware, 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

Contributing

See the contributing guide

About

Go framework generating OpenAPI 3.0 schema from source code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.4%
  • Makefile 1.6%