flow

package module
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: MIT Imports: 28 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 Nil = NotExistError("flow-redis: key not exist")

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)

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

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

启动服务

func SetCorsConfig added in v1.3.3

func SetCorsConfig(corsConfig *CorsConfig)

设置跨域配置

func SetCurlConfig added in v1.3.3

func SetCurlConfig(curlConfig *CurlConfig)

设置httpclient配置

func SetJwtConfig added in v1.4.4

func SetJwtConfig(jwtConfig *JwtConfig)

设置JWT配置

func SetLoggerConfig added in v1.2.0

func SetLoggerConfig(loggerConfig *LoggerConfig)

设置日志配置

func SetNotFoundHandle added in v1.0.3

func SetNotFoundHandle(nfh NotFoundHandle)

func SetOrmConfig added in v1.2.0

func SetOrmConfig(ormConfig *OrmConfig)

设置数据库配置

func SetPanicHandler added in v1.0.3

func SetPanicHandler(ph PanicHandler)

func SetRedisConfig added in v1.3.3

func SetRedisConfig(redisConfig *RedisConfig)

设置redis配置

func SetServerConfig added in v1.2.0

func SetServerConfig(serverConfig *ServerConfig)

设置服务配置

func Use added in v1.0.3

func Use(m Middleware)

添加中间件

Types

type Application

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

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

定义服务的APP

func (*Application) GetCorsConfig added in v1.5.9

func (app *Application) GetCorsConfig() *CorsConfig

获取跨域服务

func (*Application) GetCurlConfig added in v1.5.9

func (app *Application) GetCurlConfig() *CurlConfig

获取httpclient配置

func (*Application) GetJwtConfig added in v1.5.9

func (app *Application) GetJwtConfig() *JwtConfig

获取JWT配置

func (*Application) GetLoggerConfig added in v1.5.9

func (app *Application) GetLoggerConfig() *LoggerConfig

获取日志服务

func (*Application) GetOrmConfig added in v1.5.9

func (app *Application) GetOrmConfig() *OrmConfig

获取数据库配置

func (*Application) GetRedisConfig added in v1.5.9

func (app *Application) GetRedisConfig() *RedisConfig

获取redis配置

func (*Application) GetServerConfig added in v1.5.9

func (app *Application) GetServerConfig() *ServerConfig

获取服务配置

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 Conditions added in v1.4.9

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

func (*Conditions) Add added in v1.4.9

func (c *Conditions) Add(columnName, op string, val interface{}, table ...string) *Conditions

添加查询条件,可以链式处理

func (*Conditions) Get added in v1.4.9

func (c *Conditions) Get() []*OrmWhere

type Context

type Context struct {
	Logger *log.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 (*Context) Download

func (c *Context) Download(filePath string)

Download 下载文件

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) SaveUploadedFile added in v1.4.9

func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string, flag int) error

SaveUploadedFile 保存上传的文件到指定位置

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 {
	Enable         bool // 是否开启跨域支持
	AllowOrigin    string
	AllowedHeaders string
	AllowedMethods string
}

定义跨域配置

type Curl added in v1.3.3

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

定义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 // 统一请求的头信息
}

定义httpclient配置

type CurlResult added in v1.3.3

type CurlResult struct {
	*resty.Response
}

定义返回的结果

func (*CurlResult) Parse added in v1.3.3

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

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

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 Fields added in v1.4.9

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

定义查询字符段的结构体

func (*Fields) Add added in v1.4.9

func (f *Fields) Add(column string, table ...string) *Fields

添加查询字段,可以链式处理

func (*Fields) Get added in v1.4.9

func (f *Fields) Get() []*OrmColumn

type Handler

type Handler func(ctx *Context)

定义路由处理器

type Jwt added in v1.4.4

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

定义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        // 秘钥
}

定义JWT配置

type LoggerConfig added in v1.2.0

type LoggerConfig struct {
	LoggerLevel string
	LoggerPath  string
}

定义日志配置

type Middleware

type Middleware func(ctx *Context, next Next)

定义中间件接口

type Next

type Next func()

type NotExistError added in v1.3.3

type NotExistError string

定义redis键不存在错误对象

func (NotExistError) Error added in v1.3.3

func (e NotExistError) Error() string

func (NotExistError) NotExistError added in v1.3.3

func (NotExistError) NotExistError()

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 {
	Op       *OrmOp       // 数据库查询条件操作符对象
	JoinType *OrmJoinType // 数据库JOIN表类型对象
	// contains filtered or unexported fields
}

定义数据库操作对象

func (*Orm) Count added in v1.2.6

func (orm *Orm) Count(count *int64, fromTable *OrmFromTable, conditions []*OrmWhere) error

返回查询的总条数

func (*Orm) DB added in v1.2.6

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

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

func (*Orm) NewConditions added in v1.4.9

func (orm *Orm) NewConditions() *Conditions

func (*Orm) NewFields added in v1.4.9

func (orm *Orm) NewFields() *Fields

func (*Orm) Query added in v1.2.6

func (orm *Orm) Query(dest interface{}, fields interface{}, fromTable *OrmFromTable, conditions []*OrmWhere, orderBy []*OrmOrderBy, limit *OrmLimit, groupBy *OrmGroupBy) error

数据库查询方法

type OrmColumn added in v1.2.6

type OrmColumn struct {
	Table  string // 表名
	Column string // 列名
	Alias  string // 别名
}

定义数据库表列结构

type OrmConfig added in v1.2.0

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

定义数据库配置

type OrmFromTable added in v1.2.6

type OrmFromTable struct {
	Table string     // 表名
	Alias string     // 别名
	Joins []*OrmJoin // JOIN表集合
}

定义数据库查询表结构

type OrmGroupBy added in v1.2.6

type OrmGroupBy struct {
	Columns []*OrmColumn // 列集合
	Having  []*OrmWhere  // having条件集合
}

定义数据库GROUP BY结构

type OrmJoin added in v1.2.6

type OrmJoin struct {
	Type  string      // JOIN类型
	Table string      // 表名
	Alias string      // 别名
	ON    []*OrmWhere // JOIN条件
}

定义数据库JOIN表结构

type OrmJoinType added in v1.2.7

type OrmJoinType struct {
	CrossJoin string
	InnerJoin string
	LeftJoin  string
	RightJoin string
}

定义数据库JOIN表类型

type OrmLimit added in v1.2.6

type OrmLimit struct {
	Limit  int
	Offset int
}

定义数据库LIMIT结构

type OrmOp added in v1.2.6

type OrmOp struct {
	Eq   string
	Gt   string
	Gte  string
	Lt   string
	Lte  string
	IN   string
	Like string
	Or   string
}

定义数据库查询条件操作符

type OrmOrderBy added in v1.2.6

type OrmOrderBy struct {
	Column *OrmColumn // 表列
	Desc   bool       // 是否是倒序
}

定义数据库ORDER BY结构

type OrmPool added in v1.2.0

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

定义数据库连接池配置

type OrmWhere added in v1.2.6

type OrmWhere struct {
	Column *OrmColumn  // 表列
	Opt    string      // 操作符
	Value  interface{} //条件的值
}

定义数据库条件结构

type PanicHandler added in v1.0.2

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

type RedisClient added in v1.3.3

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

定义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) 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) GetWithOutPrefix added in v1.7.9

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

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
}

定义redis配置结构

type RedisResult added in v1.4.9

type RedisResult string

定义返回的结果

func (RedisResult) Parse added in v1.4.9

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

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

func (RedisResult) Raw added in v1.4.9

func (rr RedisResult) Raw() 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 GetRouterGroup added in v1.6.2

func GetRouterGroup() *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

添加中间件

type ServerConfig added in v1.2.0

type ServerConfig struct {
	AppName    string // 应用名称
	Proxy      bool   // 是否是代理模式
	Host       string // 服务启动地址
	Port       int    // 服务端口
	StaticPath 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
}

type TaskResult added in v1.8.4

type TaskResult struct {
	Err  error
	Data interface{}
}

Directories

Path Synopsis
utils

Jump to

Keyboard shortcuts

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