Skip to content

Latest commit

 

History

History
59 lines (40 loc) · 1.31 KB

README_EN.md

File metadata and controls

59 lines (40 loc) · 1.31 KB

Pi

build.yaml Go Reference

A pi is your good helper to build a clean JSON API server using Golang Generics.

Code Sample

type UserData struct {
    Name string
    Password string
}

var h pi.HandlerFunc = func (ctx pi.Context) error {
    data := &UserData{}
    err := pi.Format(ctx, data)
    if err != nil {
        return pi.NewError(400, err.Error())
    }

    // do sth. actions...

    return ctx.Text("hello, world!")
}

sm := pi.NewServerMux(context.Background())
sm.Post("/api/v1/users", h)

http.ListenAndServe("localhost:8080", sm)

Install

go get -u github.com/go-laeo/pi

Features

  • Fast routing, routes group, route params and wildcard route
  • net/http compatible (pi.HandlerFunc is a http.Handler)
  • Auto Manually decode HTTP body by using pi.Format[T any]()
  • Middleware supports by using pi.(ServerMux).Use() or pi.(HandlerFunc).Connect()
  • Built-in pi.FileServer for SPA
  • No third-party depdencies
  • Unit tests and benchmarks

Examples

See _examples folder.

Related Projects

License

Apache 2.0 License