Skip to content

Latest commit

 

History

History
122 lines (91 loc) · 2.09 KB

README.md

File metadata and controls

122 lines (91 loc) · 2.09 KB

angle

angle is a Go framework with battery included.

build Go Reference GitHub

Highlight Features

  • Dependency Injection via fx.
  • Fast structure log via zerolog.
  • And more...

Getting Started

Install angle:

go get github.com/go-angle/angle

Create config.yml:

name: minimal
stage: development

Then here is the code:

package main

import (
	"github.com/go-angle/angle"
	"github.com/go-angle/angle/log"
)

func main() {
	ch, _, err := angle.Start("config.yml")
	if err != nil {
		log.Fatalf("bootstrap failed with error: %v", err)
	}
	<-ch
	angle.Stop()
}

Now we can run it:

go run main.go

Automatically Binding

package main

import (
	"errors"

	"github.com/gin-gonic/gin"
	"github.com/go-angle/angle"
	"github.com/go-angle/angle/di"
	"github.com/go-angle/angle/gh"
	"github.com/go-angle/angle/log"
	"go.uber.org/fx"
)

func main() {
	ch, _, err := angle.Start("config.yml")
	if err != nil {
		log.Fatalf("bootstrap failed with error: %v", err)
	}
	<-ch
	angle.Stop()
}

type routerParams struct {
	fx.In

	Default *gin.RouterGroup `name:"api"`
}

func init() {
	gh.ProvideRouterGroup("api", func(app *gh.App) *gin.RouterGroup {
		return app.Engine.Group("api")
	})

	di.Invoke(func(r routerParams) {
		r.Default.POST("/users", gh.MustBind(createUser).HandlerFunc())
	})
}

type UserReq struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

type UserResponse struct {
	Ok bool `json:"ok"`
	ID int  `json:"id"`
}

func createUser(req *UserReq) (*UserResponse, error) {
	if req.Age <= 0 {
		return nil, errors.New("no, it's impossible")
	}
	return &UserResponse{
		Ok: true,
		ID: 1,
	}, nil
}

More

More details please see examples.