angle

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

README

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 impossiable")
	}
	return &UserResponse{
		Ok: true,
		ID: 1,
	}, nil
}

More

More details please see examples.

Documentation

Overview

Package angle is a Go framework with battery included.

Index

Constants

View Source
const (
	// Version of current.
	Version = "v0.1.0"
)

Variables

This section is empty.

Functions

func Err

func Err() error

Err returns error of angle.

func RunOnce

func RunOnce(configPath string, invokes ...interface{}) (cancel context.CancelFunc, err error)

RunOnce running functions during angle enviroment context.

func Start

func Start(configPath string, invokes ...interface{}) (<-chan os.Signal, context.CancelFunc, error)

Start start app.

func Stop

func Stop(timeout ...time.Duration) (cancel context.CancelFunc, err error)

Stop stop app.

Types

This section is empty.

Directories

Path Synopsis
Package di is a wrapper of fx, which allows to use DI across the whole lifecycle.
Package di is a wrapper of fx, which allows to use DI across the whole lifecycle.
examples
gh
Package gh is an abbreviation of gin http.
Package gh is an abbreviation of gin http.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL