flow

package module
v1.10.4 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 33 Imported by: 2

README

flow

flow是一个golang的web框架,使用koajs的洋葱圈中间件模型,框架内置了Orm,Redis,HttpClient,Jwt等工具,得益于httprouter ,性能提高30倍

安装

  • go get -u github.com/funswe/flow

Server配置

type ServerConfig struct {
	AppName    string // 应用名称,默认值flow
	Proxy      bool   // 是否是代理模式,默认值false
	Host       string // 服务启动地址,默认值127.0.0.1
	Port       int    // 服务端口,默认值9505
	StaticPath string // 服务器静态资源路径,默认值当前目录下的statics
}

Logger配置

日志使用的是logrus ,使用rotatelogs 按日期分割日志

type LoggerConfig struct {
	LoggerLevel string // 日志级别,默认值debug
	LoggerPath  string // 日志存放目录,默认值当前目录下的logs
}

Orm配置

orm框架使用的是gorm ,暂时只支持mysql

type OrmConfig struct {
	Enable   bool // 是否启用orm,默认值false
	UserName string // 数据库用户名
	Password string // 数据库密码
	DbName   string // 数据库名
	Host     string // 数据库地址,默认值127.0.0.1
	Port     int // 数据库端口,默认值3306
	Pool     *OrmPool // 数据库连接池相关配置
}

type OrmPool struct {
	MaxIdle         int // 连接池最大空闲链接,默认值5
	MaxOpen         int // 连接池最大连接数,默认值10
	ConnMaxLifeTime int64 // 连接最长存活期,超过这个时间连接将不再被复用,单位秒,默认值25000
	ConnMaxIdleTime int64 // 连接池里面的连接最大空闲时长,单位秒,默认值10
}

Redis配置

redis使用的是go-redis

type RedisConfig struct {
	Enable   bool // 是否启用redis,默认值false
	Password string // redis的密码
	DbNum    int // redis的库,默认值0
	Host     string // redis的地址,默认值127.0.0.1
	Port     int // redis的端口,默认值6379
	Prefix   string // redis的key前缀,默认值flow
}

HttpClient配置

httpclient使用的是go-resty

type CurlConfig struct {
	Timeout time.Duration     // 请求的超时时间,单位秒,默认值10
	Headers map[string]string // 统一请求的头信息
}

Jwt配置

jwt使用的是jwt-go

type JwtConfig struct {
	Timeout   time.Duration // 请求的超时时间,单位小时,默认值24
	SecretKey string        // 秘钥
}

跨域配置

type CorsConfig struct {
	Enable         bool // 是否开启跨域支持
	AllowOrigin    string // 跨域支持的域,默认值*
	AllowedHeaders string // 跨域支持的头
	AllowedMethods string // 跨域支持的请求方法,默认值GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE
}

示例

1、返回文本

func main() {
	flow.GET("/hello", func(ctx *flow.Context) {
		ctx.Body("hello, flow")
	})
	log.Fatal(flow.Run())
}

启动程序,在浏览器里访问http://localhost:9505/hello ,可以看到浏览器返回hello, flow

2、返回json

func main() {
	flow.GET("/json", func(ctx *flow.Context) {
		ctx.Json(map[string]interface{}{
			"msg": "hello, flow",
		})
	})
	log.Fatal(flow.Run())
}

启动程序,在浏览器里访问http://localhost:9505/json ,可以看到浏览器返回json字符串:{"msg": "hello, flow"},Content-Type: application/json; charset=utf-8

3、获取请求参数

func main() {
	flow.GET("/param/:name", func(ctx *flow.Context) {
		name := ctx.GetStringParam("name")
		age := ctx.GetIntParam("age")
		ctx.Json(map[string]interface{}{
			"name": name,
			"age":  age,
		})
	})
	log.Fatal(flow.Run())
}

4、绑定参数

func main() {
	param := struct {
		Name string
		Age  int
	}{}
	flow.GET("/param/:name", func(ctx *flow.Context) {
		err := ctx.Parse(&param)
		if err != nil {
			panic(err)
		}
		ctx.Json(map[string]interface{}{
			"name": param.Name,
			"age":  param.Age,
		})
	})
	log.Fatal(flow.Run())
}

5、中间件使用

func main() {
	flow.Use(func(ctx *flow.Context, next flow.Next) {
		fmt.Println("mid1->start,time==", time.Now().UnixNano())
		next()
		fmt.Println("mid1->end,time===", time.Now().UnixNano())
	})
	flow.Use(func(ctx *flow.Context, next flow.Next) {
		fmt.Println("mid2->start,time==", time.Now().UnixNano())
		next()
		fmt.Println("mid2->end,time===", time.Now().UnixNano())
	})
	flow.GET("/middleware", func(ctx *flow.Context) {
		ctx.Body("middleware")
	})
	log.Fatal(flow.Run())
}

6、文件下载

func main() {
	flow.GET("/download", func(ctx *flow.Context) {
		ctx.Download("test-file.zip")
	})
	log.Fatal(flow.Run())
}

更多例子

Documentation

Index

Constants

View Source
const (
	HttpMethodGet     = "GET"
	HttpMethodHead    = "HEAD"
	HttpMethodOptions = "OPTIONS"
	HttpMethodPost    = "POST"
	HttpMethodPut     = "PUT"
	HttpMethodPatch   = "PATCH"
	HttpMethodDelete  = "DELETE"
)

定义请求的方法

View Source
const (
	HttpHeaderContentType             = "Content-Type"
	HttpHeaderContentLength           = "Content-Length"
	HttpHeaderTransferEncoding        = "Transfer-Encoding"
	HttpHeaderContentDisposition      = "Content-Disposition"
	HttpHeaderContentTransferEncoding = "Content-Transfer-Encoding"
	HttpHeaderExpires                 = "Expires"
	HttpHeaderCacheControl            = "Cache-Control"
	HttpHeaderEtag                    = "Etag"
	HttpHeaderXForwardedHost          = "X-Forwarded-Host"
	HttpHeaderXForwardedProto         = "X-Forwarded-Proto"
	HttpHeaderXForwardedFor           = "X-Forwarded-For"
	HttpHeaderXRealIp                 = "X-Real-Ip"
	HttpHeaderIfModifiedSince         = "If-Modified-Since"
	HttpHeaderIfNoneMatch             = "If-None-Match"
	HttpHeaderLastModified            = "Last-Modified"
	HttpHeaderXContentTypeOptions     = "X-Content-Type-Options"
	HttpHeaderXPoweredBy              = "X-Powered-By"
	HttpHeaderCorsOrigin              = "Access-Control-Allow-Origin"
	HttpHeaderCorsMethods             = "Access-Control-Allow-Methods"
	HttpHeaderCorsHeaders             = "Access-Control-Allow-Headers"
	HttpHeaderCorsMaxAge              = "Access-Control-Max-Age"
)

定义http头

View Source
const NoSelect = "NOSELECT"

Variables

This section is empty.

Functions

func ALL added in v1.0.3

func ALL(path string, handler Handler)

func AddBefore added in v1.7.2

func AddBefore(b BeforeRun)

AddBefore 添加运行前需要执行的方法

func DELETE added in v1.0.3

func DELETE(path string, handler Handler)

func ExecuteAsyncTask added in v1.9.0

func ExecuteAsyncTask(task AsyncTask)

func ExecuteTask added in v1.8.4

func ExecuteTask(task Task)

func GET added in v1.0.3

func GET(path string, handler Handler)
func HEAD(path string, handler Handler)

func NewNil added in v1.9.6

func NewNil(key string) error

func PATCH added in v1.0.3

func PATCH(path string, handler Handler)

func POST added in v1.0.3

func POST(path string, handler Handler)

func PUT added in v1.0.3

func PUT(path string, handler Handler)

func Run added in v1.0.3

func Run() error

Run 启动服务

func SetCorsConfig added in v1.3.3

func SetCorsConfig(corsConfig *CorsConfig)

SetCorsConfig 设置跨域配置

func SetCurlConfig added in v1.3.3

func SetCurlConfig(curlConfig *CurlConfig)

SetCurlConfig 设置httpclient配置

func SetJwtConfig added in v1.4.4

func SetJwtConfig(jwtConfig *JwtConfig)

SetJwtConfig 设置JWT配置

func SetLoggerConfig added in v1.2.0

func SetLoggerConfig(loggerConfig *LoggerConfig)

SetLoggerConfig 设置日志配置

func SetNotFoundHandle added in v1.0.3

func SetNotFoundHandle(nfh NotFoundHandle)

func SetOrmConfig added in v1.2.0

func SetOrmConfig(ormConfig *OrmConfig)

SetOrmConfig 设置数据库配置

func SetPanicHandler added in v1.0.3

func SetPanicHandler(ph PanicHandler)

func SetRedisConfig added in v1.3.3

func SetRedisConfig(redisConfig *RedisConfig)

SetRedisConfig 设置redis配置

func SetServerConfig added in v1.2.0

func SetServerConfig(serverConfig *ServerConfig)

SetServerConfig 设置服务配置

func StartTimer added in v1.9.23

func StartTimer(timer Timer)

func StopTimer added in v1.9.23

func StopTimer(timerName string)

func Use added in v1.0.3

func Use(m Middleware)

Use 添加中间件

Types

type Application

type Application struct {
	Logger *zap.Logger // 日志对象

	Orm   *Orm         // 数据库ORM对象,用于数据库操作
	Redis *RedisClient // redis对象,用户redis操作
	Curl  *Curl        // httpclient对象,用于发送http请求,如get,post
	Jwt   *Jwt         // JWT对象
	// contains filtered or unexported fields
}

Application 定义服务的APP

func GetApp added in v1.9.28

func GetApp() *Application

func (*Application) GetCorsConfig added in v1.5.9

func (app *Application) GetCorsConfig() *CorsConfig

GetCorsConfig 获取跨域服务

func (*Application) GetCurlConfig added in v1.5.9

func (app *Application) GetCurlConfig() *CurlConfig

GetCurlConfig 获取httpclient配置

func (*Application) GetJwtConfig added in v1.5.9

func (app *Application) GetJwtConfig() *JwtConfig

GetJwtConfig 获取JWT配置

func (*Application) GetLoggerConfig added in v1.5.9

func (app *Application) GetLoggerConfig() *LoggerConfig

GetLoggerConfig 获取日志服务

func (*Application) GetOrmConfig added in v1.5.9

func (app *Application) GetOrmConfig() *OrmConfig

GetOrmConfig 获取数据库配置

func (*Application) GetRedisConfig added in v1.5.9

func (app *Application) GetRedisConfig() *RedisConfig

GetRedisConfig 获取redis配置

func (*Application) GetServerConfig added in v1.5.9

func (app *Application) GetServerConfig() *ServerConfig

GetServerConfig 获取服务配置

type AsyncTask added in v1.9.0

type AsyncTask interface {
	GetName() string
	Aggregation(app *Application, newTask AsyncTask)
	BeforeExecute(app *Application)
	AfterExecute(app *Application)
	Execute(app *Application) *TaskResult
	Completed(app *Application, result *TaskResult)
	Timeout(app *Application)
	GetTimeout() time.Duration
	GetDelay() time.Duration
	IsTimeout() bool
}

type BeforeRun added in v1.7.2

type BeforeRun func(app *Application)

type Claims added in v1.4.4

type Claims struct {
	jwt.RegisteredClaims
	Data map[string]interface{}
}

type Context

type Context struct {
	Logger *zap.Logger  // 上下文的logger对象,打印日志会自动带上请求的相关参数
	Orm    *Orm         // 数据库操作对象,引用app的orm对象
	Redis  *RedisClient // redis操作对象,引用app的redis对象
	Curl   *Curl        // httpclient操作对象,引用app的curl对象
	Jwt    *Jwt         // JWT操作对象,引用app的jwt对象
	// contains filtered or unexported fields
}

Context 定义请求上下文对象

func NewAnonymousContext added in v1.9.4

func NewAnonymousContext(app *Application) *Context

NewAnonymousContext 返回一个匿名context对象

func (*Context) FormFile added in v1.4.9

func (c *Context) FormFile(name string) (*multipart.FileHeader, error)

func (*Context) GetApp added in v1.2.0

func (c *Context) GetApp() *Application

GetApp 获取app对象

func (*Context) GetBoolParam added in v1.4.9

func (c *Context) GetBoolParam(key string) (value bool)

GetBoolParam 获取请求的bool参数,如果参数类型不是bool,则会转换成bool,只支持基本类型转换

func (*Context) GetBoolParamDefault added in v1.4.9

func (c *Context) GetBoolParamDefault(key string, def bool) (value bool)

GetBoolParamDefault GetBoolParam方法的带默认值

func (*Context) GetClientIp added in v1.6.7

func (c *Context) GetClientIp() string

GetClientIp 获取请求的客户端的IP

func (*Context) GetData added in v1.4.9

func (c *Context) GetData(key string) (value interface{}, exists bool)

GetData 获取数据

func (*Context) GetFloat64Param added in v1.4.9

func (c *Context) GetFloat64Param(key string) (value float64)

GetFloat64Param 获取请求的float64参数,如果参数类型不是float64,则会转换成float64,只支持基本类型转换

func (*Context) GetFloat64ParamDefault added in v1.4.9

func (c *Context) GetFloat64ParamDefault(key string, def float64) (value float64)

GetFloat64ParamDefault GetFloat64Param方法的带默认值

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

GetHeader 获取请求的头信息

func (*Context) GetHeaders

func (c *Context) GetHeaders() map[string][]string

GetHeaders 获取请求的所有头信息

func (*Context) GetHost

func (c *Context) GetHost() string

GetHost 获取请求的HOST信息

func (*Context) GetHostname

func (c *Context) GetHostname() string

GetHostname 获取请求的hostname

func (*Context) GetHref

func (c *Context) GetHref() string

GetHref 获取请求的完整链接

func (*Context) GetInt64Param added in v1.4.9

func (c *Context) GetInt64Param(key string) (value int64)

GetInt64Param 获取请求的int64参数,如果参数类型不是int64,则会转换成int64,只支持基本类型转换

func (*Context) GetInt64ParamDefault added in v1.4.9

func (c *Context) GetInt64ParamDefault(key string, def int64) (value int64)

GetInt64ParamDefault GetInt64Param方法的带默认值

func (*Context) GetIntParam added in v1.4.9

func (c *Context) GetIntParam(key string) (value int)

GetIntParam 获取请求的int参数,如果参数类型不是int,则会转换成int,只支持基本类型转换

func (*Context) GetIntParamDefault added in v1.4.9

func (c *Context) GetIntParamDefault(key string, def int) (value int)

GetIntParamDefault GetIntParam方法的带默认值

func (*Context) GetLength

func (c *Context) GetLength() int

GetLength 获取请求的内容长度

func (*Context) GetMethod

func (c *Context) GetMethod() string

GetMethod 获取请求的方法,如GET,POST

func (*Context) GetOrigin

func (c *Context) GetOrigin() string

GetOrigin 获取请求的地址

func (*Context) GetProtocol

func (c *Context) GetProtocol() string

GetProtocol 获取请求的协议,http or https

func (*Context) GetQuery

func (c *Context) GetQuery() url.Values

GetQuery 获取请求的query参数,map格式

func (*Context) GetQuerystring

func (c *Context) GetQuerystring() string

GetQuerystring 获取请求的querystring

func (*Context) GetRawBody added in v1.7.7

func (c *Context) GetRawBody() ([]byte, error)

GetRawBody 获取原始请求实体

func (*Context) GetRawStringBody added in v1.7.8

func (c *Context) GetRawStringBody() (string, error)

GetRawStringBody 获取原始请求实体string

func (*Context) GetStringParam added in v1.4.9

func (c *Context) GetStringParam(key string) (value string)

GetStringParam 获取请求的string参数,如果参数类型不是string,则会转换成string,只支持基本类型转换

func (*Context) GetStringParamDefault added in v1.4.9

func (c *Context) GetStringParamDefault(key string, def string) (value string)

GetStringParamDefault GetStringParam方法的带默认值

func (*Context) GetUri

func (c *Context) GetUri() string

GetUri 获取请求的URI

func (*Context) GetUserAgent added in v1.0.2

func (c *Context) GetUserAgent() string

GetUserAgent 获取请求的ua

func (*Context) IsSecure

func (c *Context) IsSecure() bool

IsSecure 判断是不是https请求

func (*Context) Json added in v1.0.2

func (c *Context) Json(data map[string]interface{})

Json 返回json数据

func (*Context) Parse added in v1.0.2

func (c *Context) Parse(object interface{}) error

Parse 解析请求的参数,将参数赋值到给定的对象里

func (*Context) Redirect

func (c *Context) Redirect(url string, code int)

Redirect 设置返回的重定向地址

func (*Context) Res added in v1.9.3

func (c *Context) Res(res ResponseWriterAdapter)

Res ResponseWriterAdapter返回自定义数据

func (*Context) SetData added in v1.4.9

func (c *Context) SetData(key string, value interface{})

SetData 保存key / value数据

func (*Context) SetHeader

func (c *Context) SetHeader(key, value string) *Context

SetHeader 设置返回的头信息

func (*Context) SetLength

func (c *Context) SetLength(length int) *Context

SetLength 设置返回体的长度

func (*Context) SetStatus

func (c *Context) SetStatus(code int) *Context

SetStatus 设置返回的http状态码

type CorsConfig added in v1.3.3

type CorsConfig struct {
	AllowOrigin    string
	AllowedHeaders string
	AllowedMethods string
}

CorsConfig 定义跨域配置

type Curl added in v1.3.3

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

Curl 定义httpclient对象

func (*Curl) Get added in v1.3.3

func (c *Curl) Get(url string, data map[string]string, headers map[string]string) (*CurlResult, error)

func (*Curl) Post added in v1.3.3

func (c *Curl) Post(url string, data interface{}, headers map[string]string) (*CurlResult, error)

type CurlConfig added in v1.3.3

type CurlConfig struct {
	Timeout time.Duration     // 请求的超时时间,单位秒
	Headers map[string]string // 统一请求的头信息
}

CurlConfig 定义httpclient配置

type CurlResult added in v1.3.3

type CurlResult struct {
	*resty.Response
}

CurlResult 定义返回的结果

func (*CurlResult) Parse added in v1.3.3

func (cr *CurlResult) Parse(v interface{}) error

Parse 将返回的结果定义到给定的对象里

type FieldValidateError added in v1.4.9

type FieldValidateError struct {
	Type  string
	Value interface{}
	Field string
	Param string
}

func (*FieldValidateError) Error added in v1.4.9

func (e *FieldValidateError) Error() string

type Handler

type Handler func(ctx *Context)

Handler 定义路由处理器

type Jwt added in v1.4.4

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

Jwt 定义JWT对象

func (*Jwt) Sign added in v1.4.4

func (j *Jwt) Sign(data map[string]interface{}) (string, error)

func (*Jwt) Valid added in v1.4.4

func (j *Jwt) Valid(token string) (map[string]interface{}, error)

type JwtConfig added in v1.4.4

type JwtConfig struct {
	Timeout   time.Duration // 请求的超时时间,单位小时
	SecretKey string        // 秘钥
}

JwtConfig 定义JWT配置

type LoggerConfig added in v1.2.0

type LoggerConfig struct {
	LoggerLevel  string
	LoggerPath   string
	LoggerMaxAge int64
	FormatJson   bool
}

LoggerConfig 定义日志配置

type Middleware

type Middleware func(ctx *Context, next Next)

Middleware 定义中间件接口

type Model added in v1.2.0

type Model interface {
	TableName() string
	Alias() string
}

type Next

type Next func()

type NotExistError added in v1.3.3

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

NotExistError 定义redis键不存在错误对象

func (NotExistError) Error added in v1.3.3

func (e NotExistError) Error() string

type NotFoundHandle added in v1.0.2

type NotFoundHandle func(w http.ResponseWriter, r *http.Request)

func (NotFoundHandle) ServeHTTP added in v1.0.2

func (f NotFoundHandle) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Orm added in v1.2.0

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

Orm 定义数据库操作对象

func (*Orm) DB added in v1.2.6

func (orm *Orm) DB() *gorm.DB

DB 返回gorm db对象,用于原生查询使用

type OrmConfig added in v1.2.0

type OrmConfig struct {
	UserName string
	Password string
	DbName   string
	Host     string
	Port     int
	Pool     *OrmPool
}

OrmConfig 定义数据库配置

type OrmPool added in v1.2.0

type OrmPool struct {
	MaxIdle         int
	MaxOpen         int
	ConnMaxLifeTime int64
	ConnMaxIdleTime int64
}

OrmPool 定义数据库连接池配置

type PanicHandler added in v1.0.2

type PanicHandler func(http.ResponseWriter, *http.Request, interface{})

type QueryBuilder added in v1.9.8

type QueryBuilder[T Model] struct {
	Model      T
	DB         *gorm.DB
	Conditions []map[string]interface{}
	Fields     []string
	OrderBy    string
	Limit      clause.Limit
	Relations  []Relation
	GroupBy    string
}

func (*QueryBuilder[T]) FindOne added in v1.9.15

func (q *QueryBuilder[T]) FindOne() (*T, error)

func (*QueryBuilder[T]) GetHasOneJoinSelectFields added in v1.9.26

func (q *QueryBuilder[T]) GetHasOneJoinSelectFields(model Model, as string) []string

func (*QueryBuilder[T]) GetSelectFields added in v1.9.15

func (q *QueryBuilder[T]) GetSelectFields(model Model) []string

func (*QueryBuilder[T]) Query added in v1.9.8

func (q *QueryBuilder[T]) Query() (int64, *[]T, error)

type RedisClient added in v1.3.3

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

RedisClient 定义redis操作对象

func (*RedisClient) Close added in v1.4.9

func (rd *RedisClient) Close() error

func (*RedisClient) Delete added in v1.4.9

func (rd *RedisClient) Delete(key string) error

func (*RedisClient) DeleteKeys added in v1.9.26

func (rd *RedisClient) DeleteKeys(keyPrefix string) error

func (*RedisClient) DeleteKeysWithOutPrefix added in v1.9.26

func (rd *RedisClient) DeleteKeysWithOutPrefix(keyPrefix string) error

func (*RedisClient) DeleteWithOutPrefix added in v1.7.9

func (rd *RedisClient) DeleteWithOutPrefix(key string) error

func (*RedisClient) Get added in v1.3.3

func (rd *RedisClient) Get(key string) (RedisResult, error)

func (*RedisClient) GetAllKeys added in v1.9.26

func (rd *RedisClient) GetAllKeys(keyPrefix string) ([]string, error)

func (*RedisClient) GetAllKeysWithOutPrefix added in v1.9.26

func (rd *RedisClient) GetAllKeysWithOutPrefix(keyPrefix string) ([]string, error)

func (*RedisClient) GetClient added in v1.10.4

func (rd *RedisClient) GetClient() *redis.Client

func (*RedisClient) GetWithOutPrefix added in v1.7.9

func (rd *RedisClient) GetWithOutPrefix(key string) (RedisResult, error)

func (*RedisClient) IsNil added in v1.9.6

func (rd *RedisClient) IsNil(err error) bool

func (*RedisClient) Set added in v1.3.3

func (rd *RedisClient) Set(key string, value interface{}, expiration time.Duration) error

func (*RedisClient) SetWithOutPrefix added in v1.7.9

func (rd *RedisClient) SetWithOutPrefix(key string, value interface{}, expiration time.Duration) error

type RedisConfig added in v1.3.3

type RedisConfig struct {
	Enable   bool
	Password string
	DbNum    int
	Host     string
	Port     int
	Prefix   string
}

RedisConfig 定义redis配置结构

type RedisResult added in v1.4.9

type RedisResult string

RedisResult 定义返回的结果

func (RedisResult) Parse added in v1.4.9

func (rr RedisResult) Parse(v interface{}) error

Parse 将返回的结果定义到给定的对象里

func (RedisResult) Raw added in v1.4.9

func (rr RedisResult) Raw() string

Raw 返回原始的请求字符串结果数据

type Relation added in v1.9.8

type Relation struct {
	Model     Model         // 关联的模型
	As        string        // 主表里字段的field name
	Required  bool          // true表示INNER JOIN false是LEFT JOIN
	ON        []string      // ON条件
	Fields    []string      // 查询的字段
	Relations []SubRelation // 关联
	GroupBy   string
	OrderBy   string
}

type ResponseWriterAdapter added in v1.9.3

type ResponseWriterAdapter interface {
	SetHeader(c *Context)
	Data() ([]byte, error)
}

type RouterGroup added in v1.6.2

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

func NewRouterGroup added in v1.10.0

func NewRouterGroup() *RouterGroup

func (*RouterGroup) ALL added in v1.6.2

func (rg *RouterGroup) ALL(path string, handler Handler) *RouterGroup

func (*RouterGroup) DELETE added in v1.6.2

func (rg *RouterGroup) DELETE(path string, handler Handler) *RouterGroup

func (*RouterGroup) GET added in v1.6.2

func (rg *RouterGroup) GET(path string, handler Handler) *RouterGroup

func (*RouterGroup) HEAD added in v1.6.2

func (rg *RouterGroup) HEAD(path string, handler Handler) *RouterGroup

func (*RouterGroup) PATCH added in v1.6.2

func (rg *RouterGroup) PATCH(path string, handler Handler) *RouterGroup

func (*RouterGroup) POST added in v1.6.2

func (rg *RouterGroup) POST(path string, handler Handler) *RouterGroup

func (*RouterGroup) PUT added in v1.6.2

func (rg *RouterGroup) PUT(path string, handler Handler) *RouterGroup

func (*RouterGroup) Use added in v1.6.2

func (rg *RouterGroup) Use(m Middleware) *RouterGroup

Use 添加中间件

type ServerConfig added in v1.2.0

type ServerConfig struct {
	AppName string // 应用名称
	Proxy   bool   // 是否是代理模式
	Host    string // 服务启动地址
	Port    int    // 服务端口
}

ServerConfig 定义服务配置

type SubRelation added in v1.9.26

type SubRelation struct {
	Model    Model    // 关联的模型
	As       string   // 主表里字段的field name
	Required bool     // true表示INNER JOIN false是LEFT JOIN
	ON       []string // ON条件
	Fields   []string // 查询的字段
	GroupBy  string
	OrderBy  string
}

type Task added in v1.8.4

type Task interface {
	BeforeExecute(app *Application)
	AfterExecute(app *Application)
	Execute(app *Application) *TaskResult
	Completed(app *Application, result *TaskResult)
	Timeout(app *Application)
	GetTimeout() time.Duration
	IsTimeout() bool
	GetDelay() time.Duration
}

type TaskResult added in v1.8.4

type TaskResult struct {
	Err  error
	Data interface{}
}

type Timer added in v1.9.23

type Timer interface {
	// GetName 定时器的名称
	GetName() string
	// Run 执行定时器触发时的方法
	Run(app *Application)
	// GetInterval 获取定时器的周期
	GetInterval() time.Duration
	// IsPeriodic 是否是周期性的定时器
	IsPeriodic() bool
	// IsImmediately 是否立即执行
	IsImmediately() bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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