Documentation
¶
Index ¶
- Constants
- func ALL(path string, handler Handler)
- func AddBefore(b BeforeRun)
- func DELETE(path string, handler Handler)
- func ExecuteAsyncTask(task AsyncTask)
- func ExecuteTask(task Task)
- func GET(path string, handler Handler)
- func HEAD(path string, handler Handler)
- func PATCH(path string, handler Handler)
- func POST(path string, handler Handler)
- func PUT(path string, handler Handler)
- func Run() error
- func SetCorsConfig(corsConfig *CorsConfig)
- func SetCurlConfig(curlConfig *CurlConfig)
- func SetJwtConfig(jwtConfig *JwtConfig)
- func SetLoggerConfig(loggerConfig *LoggerConfig)
- func SetNotFoundHandle(nfh NotFoundHandle)
- func SetOrmConfig(ormConfig *OrmConfig)
- func SetPanicHandler(ph PanicHandler)
- func SetRedisConfig(redisConfig *RedisConfig)
- func SetServerConfig(serverConfig *ServerConfig)
- func Use(m Middleware)
- type Application
- func (app *Application) GetCorsConfig() *CorsConfig
- func (app *Application) GetCurlConfig() *CurlConfig
- func (app *Application) GetJwtConfig() *JwtConfig
- func (app *Application) GetLoggerConfig() *LoggerConfig
- func (app *Application) GetOrmConfig() *OrmConfig
- func (app *Application) GetRedisConfig() *RedisConfig
- func (app *Application) GetServerConfig() *ServerConfig
- type AsyncTask
- type BeforeRun
- type Claims
- type Conditions
- type Context
- func (c *Context) Download(filePath string)
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) GetApp() *Application
- func (c *Context) GetBoolParam(key string) (value bool)
- func (c *Context) GetBoolParamDefault(key string, def bool) (value bool)
- func (c *Context) GetClientIp() string
- func (c *Context) GetData(key string) (value interface{}, exists bool)
- func (c *Context) GetFloat64Param(key string) (value float64)
- func (c *Context) GetFloat64ParamDefault(key string, def float64) (value float64)
- func (c *Context) GetHeader(key string) string
- func (c *Context) GetHeaders() map[string][]string
- func (c *Context) GetHost() string
- func (c *Context) GetHostname() string
- func (c *Context) GetHref() string
- func (c *Context) GetInt64Param(key string) (value int64)
- func (c *Context) GetInt64ParamDefault(key string, def int64) (value int64)
- func (c *Context) GetIntParam(key string) (value int)
- func (c *Context) GetIntParamDefault(key string, def int) (value int)
- func (c *Context) GetLength() int
- func (c *Context) GetMethod() string
- func (c *Context) GetOrigin() string
- func (c *Context) GetProtocol() string
- func (c *Context) GetQuery() url.Values
- func (c *Context) GetQuerystring() string
- func (c *Context) GetRawBody() ([]byte, error)
- func (c *Context) GetRawStringBody() (string, error)
- func (c *Context) GetStringParam(key string) (value string)
- func (c *Context) GetStringParamDefault(key string, def string) (value string)
- func (c *Context) GetUri() string
- func (c *Context) GetUserAgent() string
- func (c *Context) IsSecure() bool
- func (c *Context) Json(data map[string]interface{})
- func (c *Context) Parse(object interface{}) error
- func (c *Context) Redirect(url string, code int)
- func (c *Context) Res(res ResponseWriterAdapter)
- func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string, flag int) error
- func (c *Context) SetData(key string, value interface{})
- func (c *Context) SetHeader(key, value string) *Context
- func (c *Context) SetLength(length int) *Context
- func (c *Context) SetStatus(code int) *Context
- type CorsConfig
- type Curl
- type CurlConfig
- type CurlResult
- type FieldValidateError
- type Fields
- type Handler
- type Jwt
- type JwtConfig
- type LoggerConfig
- type Middleware
- type Next
- type NotExistError
- type NotFoundHandle
- type Orm
- type OrmColumn
- type OrmConfig
- type OrmFromTable
- type OrmGroupBy
- type OrmJoin
- type OrmJoinType
- type OrmLimit
- type OrmOp
- type OrmOrderBy
- type OrmPool
- type OrmWhere
- type PanicHandler
- type RedisClient
- func (rd *RedisClient) Close() error
- func (rd *RedisClient) Delete(key string) error
- func (rd *RedisClient) DeleteWithOutPrefix(key string) error
- func (rd *RedisClient) Get(key string) (RedisResult, error)
- func (rd *RedisClient) GetWithOutPrefix(key string) (RedisResult, error)
- func (rd *RedisClient) Set(key string, value interface{}, expiration time.Duration) error
- func (rd *RedisClient) SetWithOutPrefix(key string, value interface{}, expiration time.Duration) error
- type RedisConfig
- type RedisResult
- type ResponseWriterAdapter
- type RouterGroup
- func (rg *RouterGroup) ALL(path string, handler Handler) *RouterGroup
- func (rg *RouterGroup) DELETE(path string, handler Handler) *RouterGroup
- func (rg *RouterGroup) GET(path string, handler Handler) *RouterGroup
- func (rg *RouterGroup) HEAD(path string, handler Handler) *RouterGroup
- func (rg *RouterGroup) PATCH(path string, handler Handler) *RouterGroup
- func (rg *RouterGroup) POST(path string, handler Handler) *RouterGroup
- func (rg *RouterGroup) PUT(path string, handler Handler) *RouterGroup
- func (rg *RouterGroup) Use(m Middleware) *RouterGroup
- type ServerConfig
- type Task
- type TaskResult
Constants ¶
const ( HttpMethodGet = "GET" HttpMethodHead = "HEAD" HttpMethodOptions = "OPTIONS" HttpMethodPost = "POST" HttpMethodPut = "PUT" HttpMethodPatch = "PATCH" HttpMethodDelete = "DELETE" )
定义请求的方法
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头
const Nil = NotExistError("flow-redis: key not exist")
Variables ¶
This section is empty.
Functions ¶
func ExecuteAsyncTask ¶ added in v1.9.0
func ExecuteAsyncTask(task AsyncTask)
func ExecuteTask ¶ added in v1.8.4
func ExecuteTask(task Task)
func SetNotFoundHandle ¶ added in v1.0.3
func SetNotFoundHandle(nfh NotFoundHandle)
func SetPanicHandler ¶ added in v1.0.3
func SetPanicHandler(ph PanicHandler)
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 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) GetBoolParam ¶ added in v1.4.9
GetBoolParam 获取请求的bool参数,如果参数类型不是bool,则会转换成bool,只支持基本类型转换
func (*Context) GetBoolParamDefault ¶ added in v1.4.9
GetBoolParamDefault GetBoolParam方法的带默认值
func (*Context) GetClientIp ¶ added in v1.6.7
GetClientIp 获取请求的客户端的IP
func (*Context) GetFloat64Param ¶ added in v1.4.9
GetFloat64Param 获取请求的float64参数,如果参数类型不是float64,则会转换成float64,只支持基本类型转换
func (*Context) GetFloat64ParamDefault ¶ added in v1.4.9
GetFloat64ParamDefault GetFloat64Param方法的带默认值
func (*Context) GetHeaders ¶
GetHeaders 获取请求的所有头信息
func (*Context) GetInt64Param ¶ added in v1.4.9
GetInt64Param 获取请求的int64参数,如果参数类型不是int64,则会转换成int64,只支持基本类型转换
func (*Context) GetInt64ParamDefault ¶ added in v1.4.9
GetInt64ParamDefault GetInt64Param方法的带默认值
func (*Context) GetIntParam ¶ added in v1.4.9
GetIntParam 获取请求的int参数,如果参数类型不是int,则会转换成int,只支持基本类型转换
func (*Context) GetIntParamDefault ¶ added in v1.4.9
GetIntParamDefault GetIntParam方法的带默认值
func (*Context) GetProtocol ¶
GetProtocol 获取请求的协议,http or https
func (*Context) GetQuerystring ¶
GetQuerystring 获取请求的querystring
func (*Context) GetRawBody ¶ added in v1.7.7
GetRawBody 获取原始请求实体
func (*Context) GetRawStringBody ¶ added in v1.7.8
GetRawStringBody 获取原始请求实体string
func (*Context) GetStringParam ¶ added in v1.4.9
GetStringParam 获取请求的string参数,如果参数类型不是string,则会转换成string,只支持基本类型转换
func (*Context) GetStringParamDefault ¶ added in v1.4.9
GetStringParamDefault GetStringParam方法的带默认值
func (*Context) GetUserAgent ¶ added in v1.0.2
GetUserAgent 获取请求的ua
func (*Context) Res ¶ added in v1.9.3
func (c *Context) Res(res ResponseWriterAdapter)
Res ResponseWriterAdapter返回自定义数据
func (*Context) SaveUploadedFile ¶ added in v1.4.9
SaveUploadedFile 保存上传的文件到指定位置
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对象
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
定义返回的结果
func (*CurlResult) Parse ¶ added in v1.3.3
func (cr *CurlResult) Parse(v interface{}) error
将返回的结果定义到给定的对象里
type FieldValidateError ¶ added in v1.4.9
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
}
定义查询字符段的结构体
type LoggerConfig ¶ added in v1.2.0
定义日志配置
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) NewConditions ¶ added in v1.4.9
func (orm *Orm) NewConditions() *Conditions
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 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 OrmGroupBy ¶ added in v1.2.6
定义数据库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
定义数据库JOIN表类型
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
定义数据库ORDER BY结构
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
将返回的结果定义到给定的对象里
type ResponseWriterAdapter ¶ added in v1.9.3
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
GetDelay() time.Duration
}
type TaskResult ¶ added in v1.8.4
type TaskResult struct {
Err error
Data interface{}
}