yago

package module
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: MIT Imports: 38 Imported by: 0

README

Yago Scaffold - Web开发脚手架

avatar

目录

文档

Yago 文档

安装

首先你需要安装 Go (version 1.11+), 然后执行go get 安装yago
 go get github.com/goees/yago/yago

依赖

go >= 1.11(由于使用了 go mod 管理版本依赖)

如果想在GOPATH下用mod, 请设置 GO111MODULE=on 则在 GOPATH/src 目录下使用 go get 时也默认采用 go mod
export GO111MODULE=on

快速开始

1. 用 yago 在当前目录创建你的项目 myapp
yago init -a myapp
2. 进入目录初始化
cd myapp/
go mod init
3. 构建
go build
4. 创建属于自己的配置文件,并启动
sh env.init.sh yourname
./myapp
5. 控制是否需要在此机器上开启 task 任务,有两种方式
  • 修改配置文件中的 app.task_enable,默认为开启
  • 修改环境变量 export {{配置文件中的app_name}}_APP_TASK_ENABLE=1, 1 表示开启,0 表示关闭,配置文件与环境变量同时存在时环境变量生效
Goland 配置 mod
  1. Preferences -> Go -> Go modules(vgo)

  1. 如果还有标红的提示,点击 Sync packages

感谢

gin cron cobra xorm logrus beego

Documentation

Index

Constants

View Source
const CtxParamsKey = "__PARAMS__"

Variables

View Source
var (
	E            = Err("1=") // custom error
	ErrParam     = Err("2=")
	ErrSign      = Err("3=Sign failed")
	ErrAuth      = Err("4=Auth failed")
	ErrForbidden = Err("5=Forbidden")
	ErrNotLogin  = Err("6=User not login")
	ErrSystem    = Err("7=System error")
	ErrOperate   = Err("8=")
	ErrUnknown   = Err("9=Unknown error")
)
View Source
var CmdRouterMap = make(map[string]*CmdRouter)
View Source
var Component = new(components)
View Source
var HttpRouterMap = make(map[string]*HttpRouter)
View Source
var RpcServer *grpc.Server
View Source
var TaskCloseChan = make(chan int)
View Source
var TaskRouterList []*TaskRouter

Functions

func AddCmdRouter

func AddCmdRouter(use, short string, action CmdHandlerFunc, args ...ICmdArg)

func AddHttpRouter

func AddHttpRouter(url, method string, action HttpHandlerFunc, h HttpInterface, md ...interface{})

func AddTaskRouter

func AddTaskRouter(spec string, action TaskHandlerFunc)

func GetAppName added in v1.4.10

func GetAppName() string

func GetLang added in v1.3.1

func GetLang() string

func GetTranslator added in v1.3.1

func GetTranslator(lang ...string) ut.Translator

func Hostname

func Hostname() string

func IsEnvDev

func IsEnvDev() bool

func IsEnvProd

func IsEnvProd() bool

func RestartApp

func RestartApp() error

func SetHttpNoRouter

func SetHttpNoRouter(action HttpHandlerFunc)

func WrapErr added in v1.6.0

func WrapErr(ye Err, err error) error

返回业务报错(业务报错给接口展示),包裹系统错误(系统错误转到日志记录)

Types

type App

type App struct {
	// 是否开启debug模式
	DebugMode bool

	// http run mode
	HttpRunMode string
	// 开启http服务
	HttpEnable bool
	// http路由配置
	HttpRouters []*HttpRouter

	// https 证书配置
	HttpSslOn    bool
	HttpCertFile string
	HttpKeyFile  string
	// http html 模版配置
	HttpViewRender bool
	HttpViewPath   string
	HttpStaticPath string
	// http cors 跨域配置
	HttpCorsAllowAllOrigins  bool
	HttpCorsAllowOrigins     []string
	HttpCorsAllowMethods     []string
	HttpCorsAllowHeaders     []string
	HttpCorsExposeHeaders    []string
	HttpCorsAllowCredentials bool
	HttpCorsMaxAge           time.Duration
	// http gzip 压缩
	HttpGzipOn    bool
	HttpGzipLevel int
	// http pprof
	HttpPprof bool
	// http biz log
	HttpBizLogOn bool

	// 开启task服务
	TaskEnable bool
	// task路由配置
	TaskRouters []*TaskRouter

	// rpc
	RpcEnable bool
	// contains filtered or unexported fields
}

func NewApp

func NewApp() *App

func (*App) Close

func (a *App) Close()

func (*App) Run

func (a *App) Run()

type AppConfig

type AppConfig struct {
	*viper.Viper
}
var Config *AppConfig

func NewAppConfig

func NewAppConfig(cfgPath string) *AppConfig

func (*AppConfig) ReadFileConfig added in v1.6.0

func (c *AppConfig) ReadFileConfig(cfgPath string) error

type Cmd

type Cmd struct {
	*cobra.Command
}

func NewCmd

func NewCmd() *Cmd

func (*Cmd) LoadCmdRouter

func (c *Cmd) LoadCmdRouter()

func (*Cmd) RunCmd

func (c *Cmd) RunCmd()

type CmdArg

type CmdArg = CmdStringArg

type CmdBoolArg

type CmdBoolArg struct {
	Name      string
	Shorthand string
	Usage     string
	Required  bool
	Value     bool
}

func (CmdBoolArg) SetFlag

func (c CmdBoolArg) SetFlag(cmd *cobra.Command)

type CmdDurationArg

type CmdDurationArg struct {
	Name      string
	Shorthand string
	Usage     string
	Required  bool
	Value     time.Duration
}

func (CmdDurationArg) SetFlag

func (c CmdDurationArg) SetFlag(cmd *cobra.Command)

type CmdFloat64Arg

type CmdFloat64Arg struct {
	Name      string
	Shorthand string
	Usage     string
	Required  bool
	Value     float64
}

func (CmdFloat64Arg) SetFlag

func (c CmdFloat64Arg) SetFlag(cmd *cobra.Command)

type CmdHandlerFunc

type CmdHandlerFunc func(cmd *cobra.Command, args []string)

cmd

type CmdInt64Arg

type CmdInt64Arg struct {
	Name      string
	Shorthand string
	Usage     string
	Required  bool
	Value     int64
}

func (CmdInt64Arg) SetFlag

func (c CmdInt64Arg) SetFlag(cmd *cobra.Command)

type CmdIntArg

type CmdIntArg struct {
	Name      string
	Shorthand string
	Usage     string
	Required  bool
	Value     int
}

func (CmdIntArg) SetFlag

func (c CmdIntArg) SetFlag(cmd *cobra.Command)

type CmdIntSliceArg

type CmdIntSliceArg struct {
	Name      string
	Shorthand string
	Usage     string
	Required  bool
	Value     []int
}

func (CmdIntSliceArg) SetFlag

func (c CmdIntSliceArg) SetFlag(cmd *cobra.Command)

type CmdRouter

type CmdRouter struct {
	Use    string
	Short  string
	Action CmdHandlerFunc
	Args   []ICmdArg
}

type CmdStringArg

type CmdStringArg struct {
	Name      string
	Shorthand string
	Usage     string
	Required  bool
	Value     string
}

func (CmdStringArg) SetFlag

func (c CmdStringArg) SetFlag(cmd *cobra.Command)

type CmdStringSliceArg

type CmdStringSliceArg struct {
	Name      string
	Shorthand string
	Usage     string
	Required  bool
	Value     []string
}

func (CmdStringSliceArg) SetFlag

func (c CmdStringSliceArg) SetFlag(cmd *cobra.Command)

type Ctx

type Ctx struct {
	*gin.Context
	// contains filtered or unexported fields
}

func NewCtx

func NewCtx(c *gin.Context) *Ctx

func (*Ctx) Copy added in v1.6.0

func (c *Ctx) Copy() *Ctx

func (*Ctx) GetError added in v1.6.0

func (c *Ctx) GetError() error

func (*Ctx) GetFileContent added in v1.4.10

func (c *Ctx) GetFileContent(key string) ([]byte, error)

func (*Ctx) GetResponse

func (c *Ctx) GetResponse() (*ResponseBody, bool)

func (*Ctx) SetData

func (c *Ctx) SetData(data interface{})

func (*Ctx) SetDataOrErr

func (c *Ctx) SetDataOrErr(data interface{}, err interface{})

func (*Ctx) SetError

func (c *Ctx) SetError(err interface{})

type Err

type Err string

func NewErr

func NewErr(err interface{}, args ...interface{}) Err

生成通用错误, 接受通用的 error 类型或者是 string 类型 eg. yago.NewErr(yago.Forbidden, "you are not permitted") eg. yago.NewErr(errors.New("err occur")) eg. yago.NewErr("something is error") eg. yago.NewErr("%s is err","query")

func (Err) Code

func (e Err) Code() int

func (Err) Error

func (e Err) Error() string

func (Err) HasErr

func (e Err) HasErr() bool

Deprecated

func (Err) String

func (e Err) String() string

type HttpHandlerFunc

type HttpHandlerFunc func(c *Ctx)

http

type HttpInterface

type HttpInterface interface {
	BeforeAction(c *Ctx) error
	AfterAction(c *Ctx)
}

type HttpRouter

type HttpRouter struct {
	Url    string
	Method string
	Action HttpHandlerFunc

	Metadata interface{}
	// contains filtered or unexported fields
}

type ICmdArg

type ICmdArg interface {
	SetFlag(cmd *cobra.Command)
}

type ResponseBody

type ResponseBody struct {
	ErrNo  int         `json:"errno"`
	ErrMsg string      `json:"errmsg"`
	Data   interface{} `json:"data"`
}

type TaskHandlerFunc

type TaskHandlerFunc func()

task

type TaskRouter

type TaskRouter struct {
	Spec   string
	Action TaskHandlerFunc
}

Directories

Path Synopsis
base
coms
mgo
orm
rds
Code generated by yago.
Code generated by yago.
app/modules/home/homerpc/homepb
Package app_homepb is a generated protocol buffer package.
Package app_homepb is a generated protocol buffer package.
libs
arr
str

Jump to

Keyboard shortcuts

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