Documentation ¶
Index ¶
- Constants
- Variables
- func GetCode(err interface{}) int
- func MakeSign(input map[string]interface{}, key string) string
- type Context
- func (c *Context) BuildJwt(data interface{}) (string, error)
- func (c *Context) Close()
- func (c *Context) GetContainer() IContainer
- func (c *Context) IsAPIServer() bool
- func (c *Context) IsCRONServer() bool
- func (c *Context) IsFlowServer() bool
- func (c *Context) IsMQCServer() bool
- func (c *Context) IsMicroServer() bool
- func (c *Context) IsRPCServer() bool
- func (c *Context) IsWSServer() bool
- func (c *Context) IsWebServer() bool
- func (c *Context) NewDLock(name string) (lk *dlock.DLock)
- func (c *Context) NewDLockByRegistry(name string, registry string) (lk *dlock.DLock, err error)
- func (c *Context) SetRPC(rpc RPCInvoker)
- type ContextRPC
- func (cr *ContextRPC) AsyncRequest(service string, header map[string]string, form map[string]interface{}, ...) rpc.IRPCResponse
- func (cr *ContextRPC) PreInit(services ...string) error
- func (cr *ContextRPC) Request(service string, header map[string]string, form map[string]interface{}, ...) (status int, r string, param map[string]string, err error)
- func (cr *ContextRPC) RequestFailRetry(service string, header map[string]string, form map[string]interface{}, ...) (status int, r string, param map[string]string, err error)
- func (cr *ContextRPC) RequestMap(service string, header map[string]string, form map[string]interface{}, ...) (status int, r map[string]interface{}, param map[string]string, err error)
- type Error
- type Exchange
- func (e *Exchange) Broadcast(v ...interface{}) error
- func (e *Exchange) Clear()
- func (e *Exchange) Notify(name string, i ...interface{}) error
- func (e *Exchange) Relate(uuid string, name string)
- func (e *Exchange) Subscribe(uuid string, f func(...interface{}) error) error
- func (e *Exchange) Unsubscribe(uuid string)
- type IContainer
- type IContextRPC
- type IData
- type IError
- type IResponse
- type IResult
- type IUUID
- type Meta
- func (i *Meta) Check(names ...string) error
- func (i *Meta) Clear()
- func (m *Meta) Get(name string) (interface{}, bool)
- func (i *Meta) GetDataTime(name string, p ...time.Time) (time.Time, error)
- func (i *Meta) GetDataTimeByFormat(name string, format string, p ...time.Time) (time.Time, error)
- func (i *Meta) GetFloat64(name string, p ...float64) float64
- func (i *Meta) GetInt(name string, p ...int) int
- func (i *Meta) GetInt64(name string, p ...int64) int64
- func (i *Meta) GetJSON() string
- func (i *Meta) GetMaps() map[string]string
- func (i *Meta) GetString(name string, p ...string) string
- func (i *Meta) Keys() []string
- func (m *Meta) Set(key string, value interface{})
- func (m *Meta) SetStrings(input map[string]string)
- func (m *Meta) Sets(i map[string]interface{})
- func (i *Meta) Translate(format string, a bool) (string, int)
- type RPCInvoker
- type Request
- func (r *Request) Bind(obj interface{}) error
- func (r *Request) BindWith(obj interface{}, contentType string) error
- func (r *Request) Body2Input(encoding ...string) (map[string]string, error)
- func (r *Request) Check(field ...string) error
- func (r *Request) CheckSign(secret string, tp ...string) (bool, error)
- func (r *Request) CheckSignAll(secret string, all bool, a string, b string, tp ...string) (bool, error)
- func (w Request) Clear()
- func (r *Request) Get(name string) (result string, b bool)
- func (w Request) GetBindWithFunc() func(i interface{}, c string) error
- func (w Request) GetBindingFunc() func(i interface{}) error
- func (w Request) GetBody(encoding ...string) (string, error)
- func (w Request) GetBodyMap(encoding ...string) (map[string]interface{}, error)
- func (r *Request) GetDataTime(name string, p ...time.Time) (time.Time, error)
- func (r *Request) GetDataTimeByFormat(name string, format string, p ...time.Time) (time.Time, error)
- func (w Request) GetFixedSecretConfig() (*conf.FixedSecretAuth, error)
- func (r *Request) GetFloat32(name string, p ...float32) float32
- func (r *Request) GetFloat64(name string, p ...float64) float64
- func (w Request) GetHeader() map[string]string
- func (r *Request) GetInt(name string, p ...int) int
- func (r *Request) GetInt64(name string, p ...int64) int64
- func (w Request) GetJWT(out interface{}) error
- func (w Request) GetJWTBody() interface{}
- func (w Request) GetJWTConfig() (*conf.JWTAuth, error)
- func (r *Request) GetKeys() []string
- func (w Request) GetMethod() string
- func (w Request) GetPath() string
- func (w Request) GetRemoteAuthConfig() (conf.ServiceAuths, error)
- func (w Request) GetRequestMap(encoding ...string) map[string]interface{}
- func (w Request) GetSharding() (int, int)
- func (r *Request) GetSignRaw(all bool, a string, b string) (string, string)
- func (r *Request) GetString(name string, p ...string) string
- func (w Request) GetUUID() string
- func (w Request) SkipJWTExclude() (bool, error)
- func (r *Request) Translate(format string, a bool) string
- type Response
- func (r *Response) GetCode(c interface{}) int
- func (r *Response) GetContent() interface{}
- func (r *Response) GetError() error
- func (r *Response) GetHTMLRenderContent() (int, interface{}, error)
- func (r *Response) GetHeaders() map[string]string
- func (r *Response) GetJSONRenderContent() (int, interface{}, error)
- func (r *Response) GetParams() map[string]interface{}
- func (r *Response) GetStatus() int
- func (r *Response) GetView() string
- func (r *Response) HTML(content interface{})
- func (r *Response) HasError(v interface{}) bool
- func (r *Response) IsRedirect() (string, bool)
- func (r *Response) IsSuccess() bool
- func (r *Response) JSON(content interface{})
- func (r *Response) MakeSign(input map[string]interface{}, key string) (string, string)
- func (r *Response) MakeSignAll(input map[string]interface{}, key string, a string, b string) (string, string)
- func (r *Response) MustContent(status int, content interface{})
- func (r *Response) NoView()
- func (r *Response) Redirect(code int, url string)
- func (r *Response) SetContentType(p string)
- func (r *Response) SetCookie(name string, value string, timeout int, domain string)
- func (r *Response) SetHTML()
- func (r *Response) SetHeader(name string, value string)
- func (r *Response) SetHeaders(h map[string]string)
- func (r *Response) SetJSON()
- func (r *Response) SetJWT(data interface{})
- func (r *Response) SetParam(key string, v interface{})
- func (r *Response) SetParams(p map[string]interface{})
- func (r *Response) SetPlain()
- func (r *Response) SetStatus(status int)
- func (r *Response) SetView(name string)
- func (r *Response) SetXML()
- func (r *Response) ShouldContent(content interface{})
- func (r *Response) ShouldStatus(status int)
- func (r *Response) Success(v interface{})
- func (r *Response) Text(content interface{})
- func (r *Response) XML(content interface{})
- type Result
- type Snowflake
Constants ¶
const ( CT_DEF = iota CT_JSON CT_XML CT_YMAL CT_HTML CT_PLAIN CT_OTHER )
const ERR_ACCEPTED = 202
const ERR_BAD_GATEWAY = 502
const ERR_BAD_REQUEST = 400 //参数错误
4请求错误(4字头)
const ERR_BANDWIDTH_LIMIT_EXCEEDED = 509
const ERR_CONFLICT = 409
const ERR_CONTINUE = 100
1消息(1字头)
const ERR_CREATED = 201
const ERR_EXPECTATION_FAILED = 417
const ERR_FAILED_DEPENDENCY = 424
const ERR_FORBIDDEN = 403
const ERR_GATEWAY_TIMEOUT = 504
const ERR_GONE = 410
const ERR_HTTP_VERSION_NOT_SUPPORTED = 505
const ERR_INSUFFICIENT_STORAGE = 507
const ERR_LENGTH_REQUIRED = 411
const ERR_LOCKED = 423
const ERR_METHOD_NOT_ALLOWED = 405
const ERR_MOVED_PERMANENTLY = 301
const ERR_MOVE_TEMPORARILY = 302
const ERR_MULTIPLE_CHOICES = 300
3重定向(3字头)
const ERR_MULTI_STATUS = 207
const ERR_NON_AUTHORITATIVE_INFORMATION = 203
const ERR_NOT_ACCEPTABLE = 406 //缺少必须参数
const ERR_NOT_EXTENDED = 510
const ERR_NOT_FOUND = 404
const ERR_NOT_IMPLEMENTED = 501
const ERR_NOT_MODIFIED = 304
const ERR_NO_CONTENT = 204
const ERR_OK = 200
2成功(2字头)
const ERR_PARTIAL_CONTENT = 206
const ERR_PAYMENT_REQUIRED = 402
const ERR_PRECONDITION_FAILED = 412
const ERR_PROCESSING = 102
const ERR_PROXY_AUTHENTICATION_REQUIRED = 407
const ERR_REQUESTED_RANGE_NOT_SATISFIABLE = 416
const ERR_REQUEST_ENTITY_TOO_LARGE = 413
const ERR_REQUEST_TIMEOUT = 408
const ERR_REQUEST_URI_TOO_LONG = 414
const ERR_RESET_CONTENT = 205
const ERR_RETRY_WITH = 449
const ERR_SEE_OTHER = 303
const ERR_SERVER_ERROR = 500 //系统繁忙
5服务器错误(5、6字头)
const ERR_SERVICE_UNAVAILABLE = 503
const ERR_SWITCHING_PROTOCOLS = 101
const ERR_SWITCH_PROXY = 306
const ERR_TEMPORARY_REDIRECT = 307
const ERR_UNAUTHORIZED = 401
const ERR_UNAVAILABLE_FOR_LEGAL_REASONS = 451
const ERR_UNORDERED_COLLECTION = 425
const ERR_UNPARSEABLE_RESPONSE_HEADERS = 600
const ERR_UNPROCESSABLE_ENTITY = 422
const ERR_UNSUPPORTED_MEDIA_TYPE = 415
const ERR_UPGRADE_REQUIRED = 426
const ERR_USE_PROXY = 305
const ERR_constIANT_ALSO_NEGOTIATES = 506
const FAILURE = 900 //明确失败
自定义状态码
Variables ¶
var ContentTypes = map[int]string{ CT_JSON: "application/json; charset=UTF-8", CT_XML: "text/xml; charset=UTF-8", CT_YMAL: "text/ymal; charset=UTF-8", CT_HTML: "text/html; charset=UTF-8", CT_PLAIN: "text/plain; charset=UTF-8", }
ContentTypes content type map
var ERR_DataNotExist = errors.New("查询的数据不存在")
var WSExchange = NewExchange()
WSExchange web socket exchange
Functions ¶
Types ¶
type Context ¶
type Context struct { Request *Request Response *Response RPC *ContextRPC Component interface{} Meta *Meta Log logger.ILogger Name string Engine string Service string // contains filtered or unexported fields }
Context 引擎执行上下文
func GetContext ¶
func GetContext(component interface{}, name string, engine string, service string, container IContainer, queryString IData, form IData, param IData, setting IData, ext map[string]interface{}, logger *logger.Logger) *Context
GetContext 从缓存池中获取一个context
func (*Context) IsMicroServer ¶
IsMicroServer 是否是远程服务api,web,rpc
func (*Context) NewDLockByRegistry ¶
NewDLockByRegistry 指定注册中心地址创建分布式锁
type ContextRPC ¶
type ContextRPC struct {
// contains filtered or unexported fields
}
ContextRPC rpc操作实例
func (*ContextRPC) AsyncRequest ¶
func (cr *ContextRPC) AsyncRequest(service string, header map[string]string, form map[string]interface{}, failFast bool) rpc.IRPCResponse
AsyncRequest 异步请求
func (*ContextRPC) Request ¶
func (cr *ContextRPC) Request(service string, header map[string]string, form map[string]interface{}, failFast bool) (status int, r string, param map[string]string, err error)
Request RPC请求
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func NewIgnoreError ¶
NewIgnoreError 当前一个可忽略的错误
type Exchange ¶
type Exchange struct {
// contains filtered or unexported fields
}
Exchange 数据交换中心
type IContainer ¶
type IContainer interface { RPCInvoker conf.ISystemConf conf.IVarConf conf.IMainConf GetRegistry() registry.IRegistry GetTags(name string) []string GetRegularCache(names ...string) (c cache.ICache) GetCache(names ...string) (c cache.ICache, err error) GetCacheBy(tpName string, name string) (c cache.ICache, err error) SaveCacheObject(tpName string, name string, f func(c conf.IConf) (cache.ICache, error)) (bool, cache.ICache, error) GetRegularDB(names ...string) (d db.IDB) GetDB(names ...string) (d db.IDB, err error) GetDBBy(tpName string, name string) (c db.IDB, err error) SaveDBObject(tpName string, name string, f func(c conf.IConf) (db.IDB, error)) (bool, db.IDB, error) GetRegularInflux(names ...string) (c influxdb.IInfluxClient) GetInflux(names ...string) (d influxdb.IInfluxClient, err error) GetInfluxBy(tpName string, name string) (c influxdb.IInfluxClient, err error) SaveInfluxObject(tpName string, name string, f func(c conf.IConf) (influxdb.IInfluxClient, error)) (bool, influxdb.IInfluxClient, error) GetRegularQueue(names ...string) (c queue.IQueue) GetQueue(names ...string) (q queue.IQueue, err error) GetQueueBy(tpName string, name string) (c queue.IQueue, err error) SaveQueueObject(tpName string, name string, f func(c conf.IConf) (queue.IQueue, error)) (bool, queue.IQueue, error) GetGlobalObject(tpName string, name string) (c interface{}, err error) SaveGlobalObject(tpName string, name string, f func(c conf.IConf) (interface{}, error)) (bool, interface{}, error) Close() error }
type IContextRPC ¶
type IContextRPC interface { PreInit(services ...string) error RequestFailRetry(service string, input map[string]interface{}, times int) (status int, r string, param map[string]string, err error) Request(service string, input map[string]interface{}, failFast bool) (status int, r string, param map[string]string, err error) RequestMap(service string, input map[string]interface{}, failFast bool) (status int, r map[string]interface{}, param map[string]string, err error) }
IContextRPC rpc基础操作
type IResponse ¶
type IResponse interface { GetContent() interface{} GetCode(interface{}) int GetStatus() int SetStatus(int) GetView() string GetParams() map[string]interface{} SetParams(v map[string]interface{}) SetParam(key string, v interface{}) GetHTMLRenderContent() (int, interface{}, error) GetJSONRenderContent() (int, interface{}, error) ShouldContent(content interface{}) MustContent(status int, content interface{}) IsRedirect() (string, bool) GetHeaders() map[string]string SetHeader(name string, value string) SetHeaders(map[string]string) SetJWT(data interface{}) ShouldStatus(status int) HasError(v interface{}) bool GetError() error IsSuccess() bool JSON(content interface{}) XML(content interface{}) Text(content interface{}) HTML(content interface{}) }
IResponse 响应
type Meta ¶
type Meta struct {
// contains filtered or unexported fields
}
Meta 元数据
func (*Meta) GetDataTime ¶
func (*Meta) GetDataTimeByFormat ¶
GetFloat64 获取float64数字
func (*Meta) GetFloat64 ¶
GetFloat64 获取float64数字
type RPCInvoker ¶
type RPCInvoker interface { PreInit(services ...string) (err error) RequestFailRetry(service string, method string, header map[string]string, input map[string]interface{}, times int) (status int, result string, params map[string]string, err error) Request(service string, method string, header map[string]string, input map[string]interface{}, failFast bool) (status int, result string, param map[string]string, err error) AsyncRequest(service string, method string, header map[string]string, input map[string]interface{}, failFast bool) rpc.IRPCResponse WaitWithFailFast(callback func(string, int, string, error), timeout time.Duration, rs ...rpc.IRPCResponse) error }
type Request ¶
type Request struct { Form *inputParams QueryString *inputParams Param *inputParams Setting *inputParams Metadata *Meta CircuitBreaker *circuitBreakerParam //熔断处理 Http *httpRequest // contains filtered or unexported fields }
Request 输入参数
func (*Request) Body2Input ¶
Body2Input 根据编码格式解码body参数,并更新input参数
func (*Request) CheckSignAll ¶
func (r *Request) CheckSignAll(secret string, all bool, a string, b string, tp ...string) (bool, error)
CheckSignAll 检查签名是否正确
func (Request) GetBindWithFunc ¶
func (Request) GetBindingFunc ¶
func (w Request) GetBindingFunc() func(i interface{}) error
func (Request) GetBodyMap ¶
func (*Request) GetDataTime ¶
GetDataTime 获取日期时间
func (*Request) GetDataTimeByFormat ¶
func (r *Request) GetDataTimeByFormat(name string, format string, p ...time.Time) (time.Time, error)
GetDataTimeByFormat 获取日期时间
func (Request) GetFixedSecretConfig ¶
func (w Request) GetFixedSecretConfig() (*conf.FixedSecretAuth, error)
GetFixedSecretConfig 获取jwt配置信息
func (*Request) GetFloat32 ¶
GetFloat32 获取float64数字
func (*Request) GetFloat64 ¶
GetFloat64 获取float64数字
func (Request) GetJWTConfig ¶
GetJWTConfig 获取jwt配置信息
func (Request) GetMethod ¶
func (w Request) GetMethod() string
func (w *extParams) Get(name string) (interface{}, bool) { v, ok := w.ext[name] return v, ok }
func (Request) GetRemoteAuthConfig ¶
func (w Request) GetRemoteAuthConfig() (conf.ServiceAuths, error)
GetRemoteAuthConfig 获取远程服务认证
func (Request) GetRequestMap ¶
func (Request) GetSharding ¶
GetSharding 获取任务分片信息(分片索引[从1开始],分片总数)
func (*Request) GetSignRaw ¶
GetSignRaw 检查签名原串
func (Request) SkipJWTExclude ¶
type Response ¶
type Response struct { Status int Content interface{} Params map[string]interface{} SkipHandle bool // contains filtered or unexported fields }
func NewResponse ¶
func NewResponse() *Response
func (*Response) GetContent ¶
func (r *Response) GetContent() interface{}
func (*Response) GetHTMLRenderContent ¶
func (*Response) GetHeaders ¶
GetHeaders 获取http头配置
func (*Response) GetJSONRenderContent ¶
func (*Response) MakeSignAll ¶
func (r *Response) MakeSignAll(input map[string]interface{}, key string, a string, b string) (string, string)
MakeSignAll 生成签名串,排序,并将key放到原串最后
func (*Response) MustContent ¶
func (*Response) SetContentType ¶
func (*Response) SetHTML ¶
func (r *Response) SetHTML()
SetTextHTML 将content type设置为text/html; charset=UTF-8
func (*Response) SetHeaders ¶
func (*Response) SetJSON ¶
func (r *Response) SetJSON()
SeTextJSON 将content type设置为application/json; charset=UTF-8
func (*Response) SetPlain ¶
func (r *Response) SetPlain()
SetTextPlain 将content type设置为text/plain; charset=UTF-8
func (*Response) SetXML ¶
func (r *Response) SetXML()
SetTextXML 将content type设置为text/xml; charset=UTF-8
func (*Response) ShouldContent ¶
func (r *Response) ShouldContent(content interface{})
func (*Response) ShouldStatus ¶
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
func NewResultf ¶
NewResultf 创建带状态码的返回对象
Source Files ¶
- context.dlock.go
- context.exchange.go
- context.ext.go
- context.go
- context.request.circuit.go
- context.request.ext.go
- context.request.go
- context.request.http.go
- context.request.meta.go
- context.request.param.go
- context.request.sign.go
- context.response.go
- context.response.param.go
- context.response.r.go
- context.response.s.go
- context.response.t.go
- context.response.w.go
- context.rpc.go
- context.snowflake.go
- context.uuid.go
- error.go
- errorCode.go
- result.go