Skip to content
/ angle Public

angle is a kick-start framework of Golang, so you don't have to start from scratch.

License

Notifications You must be signed in to change notification settings

go-angle/angle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

angle is a kick-start framework of Golang, so you don't have to start from scratch.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages