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 NewNil(key string) error
- 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 StartTimer(timer Timer)
- func StopTimer(timerName string)
- 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 Context
- 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) 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 Handler
- type Jwt
- type JwtConfig
- type LoggerConfig
- type Middleware
- type Model
- type Next
- type NotExistError
- type NotFoundHandle
- type Orm
- type OrmConfig
- type OrmPool
- type PanicHandler
- type QueryBuilder
- type RedisClient
- func (rd *RedisClient) Close() error
- func (rd *RedisClient) Delete(key string) error
- func (rd *RedisClient) DeleteKeys(keyPrefix string) error
- func (rd *RedisClient) DeleteKeysWithOutPrefix(keyPrefix string) error
- func (rd *RedisClient) DeleteWithOutPrefix(key string) error
- func (rd *RedisClient) Get(key string) (RedisResult, error)
- func (rd *RedisClient) GetAllKeys(keyPrefix string) ([]string, error)
- func (rd *RedisClient) GetAllKeysWithOutPrefix(keyPrefix string) ([]string, error)
- func (rd *RedisClient) GetClient() *redis.Client
- func (rd *RedisClient) GetWithOutPrefix(key string) (RedisResult, error)
- func (rd *RedisClient) IsNil(err error) bool
- 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 Relation
- 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 SubRelation
- type Task
- type TaskResult
- type Timer
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 NoSelect = "NOSELECT"
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 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 SetLoggerConfig ¶ added in v1.2.0
func SetLoggerConfig(loggerConfig *LoggerConfig)
SetLoggerConfig 设置日志配置
func SetNotFoundHandle ¶ added in v1.0.3
func SetNotFoundHandle(nfh NotFoundHandle)
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)
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) 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返回自定义数据
type CorsConfig ¶ added in v1.3.3
CorsConfig 定义跨域配置
type Curl ¶ added in v1.3.3
type Curl struct {
// contains filtered or unexported fields
}
Curl 定义httpclient对象
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
func (*FieldValidateError) Error ¶ added in v1.4.9
func (e *FieldValidateError) Error() string
type Jwt ¶ added in v1.4.4
type Jwt struct {
// contains filtered or unexported fields
}
Jwt 定义JWT对象
type LoggerConfig ¶ added in v1.2.0
type LoggerConfig struct { LoggerLevel string LoggerPath string LoggerMaxAge int64 FormatJson bool }
LoggerConfig 定义日志配置
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 定义数据库操作对象
type OrmConfig ¶ added in v1.2.0
type OrmConfig struct { UserName string Password string DbName string Host string Port int Pool *OrmPool }
OrmConfig 定义数据库配置
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 将返回的结果定义到给定的对象里
type ResponseWriterAdapter ¶ added in v1.9.3
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 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{} }