yago

package module
v1.3.1 Latest Latest
Warning

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

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

README

Yago Scafford

avatar

Yago web开发脚手架

目录

文档

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

如 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

已知问题及解决方案

  1. unknown import path "github.com/ugorji/go/codec": ambiguous import: found github.com/ugorji/go/codec in multiple modules 模块冲突问题

    原因参考:

    https://cloud.tencent.com/developer/article/1417112

    解决方案: 在go.mod文件最下面添加如下代码

    replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43
    

感谢

gin cron cobra xorm logrus beego

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// You can replace yago Err variable in your application,eg. yago.ErrParam = Err("4000=Param err")
	OK           = Err("0")
	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 GlobalCloseChan = make(chan int)
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)

func AddTaskRouter

func AddTaskRouter(spec string, action TaskHandlerFunc)

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 ValidateHttp

func ValidateHttp(c *Ctx, action string, labels validator.Label, rules []validator.Rule) (bool, 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

	// 开启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

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) GetResponse

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

func (*Ctx) RequestBool

func (c *Ctx) RequestBool(key string, def ...bool) bool

func (*Ctx) RequestFileContent

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

func (*Ctx) RequestFloat64

func (c *Ctx) RequestFloat64(key string, def ...float64) (float64, error)

func (*Ctx) RequestInt

func (c *Ctx) RequestInt(key string, def ...int) (int, error)

func (*Ctx) RequestInt64

func (c *Ctx) RequestInt64(key string, def ...int64) (int64, error)

func (*Ctx) RequestSliceInt

func (c *Ctx) RequestSliceInt(key string, def ...int) ([]int, error)

func (*Ctx) RequestSliceInt64

func (c *Ctx) RequestSliceInt64(key string, def ...int64) ([]int64, error)

func (*Ctx) RequestSliceString

func (c *Ctx) RequestSliceString(key string, def ...string) []string

func (*Ctx) RequestString

func (c *Ctx) RequestString(key string, def ...string) string

func (*Ctx) SetData

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

func (*Ctx) SetDataOrErr

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

func (*Ctx) SetError

func (c *Ctx) SetError(err interface{}, msgEx ...string)

func (*Ctx) Validate

func (c *Ctx) Validate() error

type Err

type Err string

func NewErr

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

生成通用错误, 接受通用的 error 类型或者是 string 类型 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

func (Err) String

func (e Err) String() string

type HttpHandlerFunc

type HttpHandlerFunc func(c *Ctx)

http

type HttpInterface

type HttpInterface interface {
	Labels() validator.Label
	Rules() []validator.Rule
	BeforeAction(c *Ctx) Err
	AfterAction(c *Ctx)
}

type HttpRouter

type HttpRouter struct {
	Url    string
	Method string
	Action HttpHandlerFunc
	// 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.
app/third/homeapi/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