Documentation
¶
Index ¶
- Constants
- Variables
- func CheckAuth(timeout int64, signature, key, cid, id, ts, userdata string) int
- func CloseLogger()
- func FillDefault(v any) error
- func GenSignature(key, cid, id, userdata string) (string, string)
- func MustInitLog(conf *LogConf)
- func MustLoad(path string, v any)
- type APIContext
- type APILogic
- type APIServer
- type CommonConf
- type EncryptionType
- type ErrorResponse
- type FloatCmd
- type FloatPair
- type GeoLocation
- type GeoPos
- type GeoRadiusQuery
- type HttpClient
- type IntCmd
- type LogConf
- type Logger
- type NewAPIContextFunc
- type OptParser
- type Option
- type Pair
- type Pipeliner
- type Pool
- type Redis
- type RedisConf
- type RedisLock
- type RedisNode
- type RestConf
- type Script
- type ServiceError
- type StringCmd
- type Z
- type ZStore
Constants ¶
const ( AuthOK = iota AuthTimestampError AuthExpireError AuthSignatureError )
const (
ParseRequestError = 20000
)
Variables ¶
var ( Debug = GetLogger().Debug Debugf = GetLogger().Debugf Debugv = GetLogger().Debugv Debugw = GetLogger().Debugw Error = GetLogger().Error Errorf = GetLogger().Errorf Errorv = GetLogger().Errorv Errorw = GetLogger().Errorw Info = GetLogger().Info Infof = GetLogger().Infof Infov = GetLogger().Infov Infow = GetLogger().Infow Slow = GetLogger().Slow Slowf = GetLogger().Slowf Slowv = GetLogger().Slowv Sloww = GetLogger().Sloww )
Functions ¶
func CloseLogger ¶
func CloseLogger()
func FillDefault ¶
func GenSignature ¶
func MustInitLog ¶
func MustInitLog(conf *LogConf)
Types ¶
type APIContext ¶
type APIContext interface {
SetLogger(log Logger) // 设置 logger
SetContext(ctx context.Context) // 设置请求 Context
Request() any // 获取请求结构体,用于收到 HTTP 请求时做请求参数校验时调用
Handler(l *APILogic) (any, error) // API 处理函数
}
APIContext 接口,每个 HTTP 请求会对应一个 APIContext 实例
type APILogic ¶
type APILogic struct {
Context any // 业务 Context
Uri string
NewAPIContext NewAPIContextFunc // 收到 HTTP 请求后,创建请求的 APIContext 回调函数
}
API 业务逻辑,每个接口对应一个该类的实例
func NewAPILogic ¶
func NewAPILogic(f NewAPIContextFunc, ctx any) *APILogic
用于创建 APILogic 使用 f 为收到 HTTP 请求后,创建请求的 APIContext 回调函数 ctx 为业务自定义内容
type APIServer ¶
type APIServer struct {
// contains filtered or unexported fields
}
APIServer 结构
func CreateAPIServerWithConf ¶
使用已初始化的配置创建 APIServer
func (*APIServer) RegisteHandler ¶
注册 API 路由 prefix 为请求 path 中的版本,如 /v1,/v2 method 为 HTTP 请求方法,如 http.MethodGet path 为访问路径 l 为请求处理的 APILogic 实例
func (*APIServer) RegisteUserHandler ¶
func (s *APIServer) RegisteUserHandler(prefix string, method string, path string, f http.HandlerFunc)
注册用户 HTTPHandler prefix 为请求 path 中的版本,如 /v1,/v2 method 为 HTTP 请求方法,如 http.MethodGet path 为访问路径 f 为用户 HTTP 请求处理函数
type CommonConf ¶ added in v1.0.2
type CommonConf struct {
ClusterId string `json:",default=test-cluster"`
InstanceId string `json:",default=test-instance"`
AuthKey string `json:",optional"`
}
func (*CommonConf) ReplaceEnv ¶ added in v1.0.2
func (c *CommonConf) ReplaceEnv()
type ErrorResponse ¶
type GeoLocation ¶
type GeoLocation = red.GeoLocation
GeoLocation is used with GeoAdd to add geospatial location.
type GeoRadiusQuery ¶
type GeoRadiusQuery = red.GeoRadiusQuery
GeoRadiusQuery is used with GeoRadius to query geospatial index.
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpClient ¶
func (*HttpClient) Body ¶
func (hc *HttpClient) Body() ([]byte, error)
func (*HttpClient) Close ¶
func (hc *HttpClient) Close()
func (*HttpClient) Do ¶
func (hc *HttpClient) Do() error
func (*HttpClient) Parse ¶
func (hc *HttpClient) Parse(val any) error
func (*HttpClient) StatusCode ¶
func (hc *HttpClient) StatusCode() int
type Logger ¶
func GetLoggerWithContext ¶
type NewAPIContextFunc ¶
type NewAPIContextFunc func() APIContext
type OptParser ¶ added in v1.0.2
type OptParser struct {
// contains filtered or unexported fields
}
func (*OptParser) GetOpt ¶ added in v1.0.2
Parse Opt, the option string optstring may contain the following elements: individual characters, and characters followed by a colon to indicate an option argument is to follow. For example, an option string "x" recognizes an option “-x”, and an option string "x:" recognizes an option and argument “-x argument”. It does not matter to getopt() if a following argument has leading white space.
type Redis ¶
func NewRedisClient ¶
type RedisLock ¶
type RedisLock struct {
// contains filtered or unexported fields
}
func (*RedisLock) BlockAcquire ¶
type ServiceError ¶
func (*ServiceError) Error ¶
func (se *ServiceError) Error() string
func (*ServiceError) GenResponse ¶
func (se *ServiceError) GenResponse(w http.ResponseWriter, err error)