gallop

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 24 Imported by: 0

README

Gallop

Go gin 快速开发脚手架,本仓库的实现思路和部分代码多数来源于https://github.com/shenyisyn/goft-gin

Gallop主要是使用inject去贯传,这个项目并实现mvc架构,对gin进行封装。用于快速开发。

使用到的开源库,排名不分先后
  1. gin-gonic/gin https://gin-gonic.com/docs/
  2. spf13/viper https://github.com/spf13/viper
  3. facebookarchive/inject https://github.com/facebookarchive/inject
  4. jinzhu/copier https://github.com/jinzhu/copier.git
  5. goframe https://goframe.org/display/gf
系统配置说明

1.集成了日志zap组件,会以json对象输出

logger:
    type: file
    path: ./logs
    level: debug # 支持debug< info< warn< error< dpanic< panic< fatal
    stack: false # 当设置为true只有>=warn的等级才会显示stack

为了方便继承,我们增加了LogFiled属性,用户自定义日志输出如增加req_id

filed:=logger.LogField{}
filed["req_id"]="xxxxxxxxxxxxx"
logger.Info("1233",filed)
//输出: {"level":"INFO","ts":"2020-08-28 14:26:32","func":"controller/hello.go:20","msg":"1233","req_id":"xxxxxxxxxxxxx"}

Documentation

Index

Constants

View Source
const RspBodyKey = "gallop_rsp_key"

Variables

This section is empty.

Functions

func AddJob

func AddJob(spec string, job cron.Job, options ...JobOption) (int, error)

AddJob 注入脚本,不支持

func Convert

func Convert(handler interface{}) gin.HandlerFunc

func GetBeanByName

func GetBeanByName(name string) (interface{}, error)

func InitFlags

func InitFlags()

InitFlags normalizes and parses the command line flags

func MidFactory

func MidFactory(h IMidHandler) gin.HandlerFunc

MidFactory 构造函数

func OpenCors

func OpenCors(engine *gin.Engine)

func RemoveJob

func RemoveJob(id int)

RemoveJob 删除脚本

func Throw

func Throw(err error)

func ThrowWithErr

func ThrowWithErr(err, base error)

func WarnWordSepNormalizeFunc

func WarnWordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName

WarnWordSepNormalizeFunc changes and warns for flags that contain "_" separators

func WordSepNormalizeFunc

func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName

WordSepNormalizeFunc changes all flags that contain "_" separators

Types

type BeforeFunc added in v1.0.0

type BeforeFunc func(app *gin.Engine)

type CloseContext added in v0.1.1

type CloseContext context.Context

type Context

type Context struct {
	*gin.Context
}

func (*Context) ClientIP added in v0.1.9

func (c *Context) ClientIP() string

func (*Context) ShouldBind

func (c *Context) ShouldBind(obj interface{}) error

func (*Context) ShouldBindHeader

func (c *Context) ShouldBindHeader(obj interface{}) error

func (*Context) ShouldBindUri

func (c *Context) ShouldBindUri(obj interface{}) error

type File

type File struct {
	Data        []byte
	ContentType string
	FileName    string
}

type FileResponder

type FileResponder func(*Context) File

func (FileResponder) RespondTo

func (f FileResponder) RespondTo() gin.HandlerFunc

type Gallop

type Gallop struct {
	// contains filtered or unexported fields
}

func Ignite

func Ignite() *Gallop

Ignite 项目初始化

func (*Gallop) Actions

func (g *Gallop) Actions(acts ...IAction) *Gallop

func (*Gallop) Banner

func (g *Gallop) Banner(banner string)

func (*Gallop) Beans

func (g *Gallop) Beans(configs ...interface{}) *Gallop

func (*Gallop) Before added in v1.0.0

func (g *Gallop) Before(funcs ...BeforeFunc) *Gallop

func (*Gallop) Job

func (g *Gallop) Job(spec string, job cron.Job, options ...JobOption) *Gallop

Job 注入脚本支持依赖对象

func (*Gallop) Launch

func (g *Gallop) Launch(addr ...string)

func (*Gallop) Modular

func (g *Gallop) Modular(name string, routers ...IRouter) *Gallop

func (*Gallop) Preload

func (g *Gallop) Preload()

Preload 预执行,便于一些不需要web的项目,如果保持程序允许用开发自行控制

func (*Gallop) Use

func (g *Gallop) Use(middes ...IMidHandler) *Gallop

func (*Gallop) Validate

func (g *Gallop) Validate(validators ...IValidator) *Gallop

type Group

type Group struct {
	*gin.RouterGroup
}

func (*Group) Any

func (group *Group) Any(relativePath string, handlers ...interface{}) *Group

Any registers a route that matches all the HTTP methods. GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.

func (*Group) DELETE

func (group *Group) DELETE(relativePath string, handlers ...interface{}) *Group

DELETE is a shortcut for router.Handle("DELETE", path, handle).

func (*Group) GET

func (group *Group) GET(relativePath string, handlers ...interface{}) *Group

GET is a shortcut for router.Handle("GET", path, handle).

func (*Group) Group

func (group *Group) Group(name string, handlers ...interface{}) *Group

func (*Group) HEAD

func (group *Group) HEAD(relativePath string, handlers ...interface{}) *Group

HEAD is a shortcut for router.Handle("HEAD", path, handle).

func (*Group) Handle

func (group *Group) Handle(httpMethod, relativePath string, handlers ...interface{}) *Group

func (*Group) Native

func (group *Group) Native() *gin.RouterGroup

HEAD is a shortcut for router.Handle("HEAD", path, handle).

func (*Group) OPTIONS

func (group *Group) OPTIONS(relativePath string, handlers ...interface{}) *Group

OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle).

func (*Group) PATCH

func (group *Group) PATCH(relativePath string, handlers ...interface{}) *Group

PATCH is a shortcut for router.Handle("PATCH", path, handle).

func (*Group) POST

func (group *Group) POST(relativePath string, handlers ...interface{}) *Group

POST is a shortcut for router.Handle("POST", path, handle).

func (*Group) PUT

func (group *Group) PUT(relativePath string, handlers ...interface{}) *Group

PUT is a shortcut for router.Handle("PUT", path, handle).

func (*Group) Use

func (group *Group) Use(middleware ...IMidHandler) *Group

type IAction

type IAction interface {
	Exec()
}

type IActionClose added in v0.1.1

type IActionClose interface {
}

type IClose added in v0.1.1

type IClose interface {
	Shutdown(CloseContext)
}

type IMidHandler

type IMidHandler func(*Context)

type IRouter

type IRouter interface {
	Builder(*Group)
}

type IValidator

type IValidator interface {
	Validate() (f validator.Func, name string)
}

type JobOption added in v0.1.5

type JobOption func(op *jobOptions)

func JobOneOption added in v0.1.5

func JobOneOption(b bool) JobOption

JobOneOption 对局属性

type Json

type Json interface{}

type JsonResponder

type JsonResponder func(*Context) Json

func (JsonResponder) RespondTo

func (j JsonResponder) RespondTo() gin.HandlerFunc

type Options

type Options struct {
	AddrPort   string
	ConfigPath string
}

Options 配置项

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions 初始化命令行参数

func (*Options) AddFlags

func (s *Options) AddFlags(fs *pflag.FlagSet)

AddFlags 增加命令行参数

type Responder

type Responder interface {
	RespondTo() gin.HandlerFunc
}

type StringResponder

type StringResponder func(*Context) string

func (StringResponder) RespondTo

func (s StringResponder) RespondTo() gin.HandlerFunc

type XML

type XML interface{}

type XMLResponder

type XMLResponder func(*Context) XML

func (XMLResponder) RespondTo

func (s XMLResponder) RespondTo() gin.HandlerFunc

Directories

Path Synopsis
infras
third_plugins

Jump to

Keyboard shortcuts

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