Documentation ¶
Index ¶
- Constants
- func HealthProbe() gin.HandlerFunc
- func InitHttp(opts *TransportOption)
- func InitMysqlClient(conf MysqlConf) (client *gorm.DB, err error)
- func NewESClient(cfg ElasticClientConfig) (*elastic.Client, error)
- func ReadyProbe() gin.HandlerFunc
- func RegHealthProbe(h gin.HandlerFunc)
- func RegReadyProbe(h gin.HandlerFunc)
- func RegisterProf()
- func RenderJson(ctx *gin.Context, code int, msg string, data interface{})
- func RenderJsonAbort(ctx *gin.Context, err error)
- func RenderJsonFail(ctx *gin.Context, err error)
- func RenderJsonSucc(ctx *gin.Context, data interface{})
- func SetErrPrintfMsg(err *Error, v ...interface{})
- func StackLogger(ctx *gin.Context, err error)
- type ApiClient
- func (client *ApiClient) GetTransPort() *http.Transport
- func (client *ApiClient) HttpGet(ctx *gin.Context, path string, opts HttpRequestOptions) (*ApiResult, error)
- func (client *ApiClient) HttpPost(ctx *gin.Context, path string, opts HttpRequestOptions) (*ApiResult, error)
- func (client *ApiClient) HttpPostJson(ctx *gin.Context, path string, opts HttpRequestOptions) (*ApiResult, error)
- type ApiResult
- type BackOffPolicy
- type DefaultRender
- type ElasticClientConfig
- type Error
- func (err Error) Equal(e error) bool
- func (err Error) Error() string
- func (err Error) Sprintf(v ...interface{}) Error
- func (err Error) Wrap(core error) error
- func (err Error) WrapPrint(core error, message string, user ...interface{}) error
- func (err Error) WrapPrintf(core error, format string, message ...interface{}) error
- type HttpRequestOptions
- func (o *HttpRequestOptions) GetBackOffPolicy() BackOffPolicy
- func (o *HttpRequestOptions) GetContentType() (cType string)
- func (o *HttpRequestOptions) GetData() (string, error)
- func (o *HttpRequestOptions) GetJsonData() (string, error)
- func (o *HttpRequestOptions) GetRequestData() (encodeData string, err error)
- func (o *HttpRequestOptions) GetRetryPolicy() RetryPolicy
- func (o *HttpRequestOptions) GetUrlData() (string, error)
- type MysqlConf
- type PprofConfig
- type Probe
- type RedisClient
- type RedisConf
- type RetryPolicy
- type TransportOption
Constants ¶
View Source
const ( EncodeJson = "_json" EncodeForm = "_form" EncodeRaw = "_raw" )
View Source
const HttpHeaderService = "SERVICE"
View Source
const HttpUrlPressureTestKey = "_call_uri"
Variables ¶
This section is empty.
Functions ¶
func HealthProbe ¶
func HealthProbe() gin.HandlerFunc
func NewESClient ¶
func NewESClient(cfg ElasticClientConfig) (*elastic.Client, error)
func ReadyProbe ¶
func ReadyProbe() gin.HandlerFunc
func RegHealthProbe ¶
func RegHealthProbe(h gin.HandlerFunc)
func RegReadyProbe ¶
func RegReadyProbe(h gin.HandlerFunc)
func RegisterProf ¶
func RegisterProf()
func RenderJsonAbort ¶
func RenderJsonFail ¶
func RenderJsonSucc ¶
func SetErrPrintfMsg ¶
func SetErrPrintfMsg(err *Error, v ...interface{})
Types ¶
type ApiClient ¶
type ApiClient struct { Service string `yaml:"service"` AppKey string `yaml:"appkey"` AppSecret string `yaml:"appsecret"` Domain string `yaml:"domain"` Timeout time.Duration `yaml:"timeout"` ConnectTimeout time.Duration `yaml:"connectTimeout"` Retry int `yaml:"retry"` HttpStat bool `yaml:"httpStat"` Host string `yaml:"host"` Proxy string `yaml:"proxy"` BasicAuth struct { Username string `yaml:"username"` Password string `yaml:"password"` } HTTPClient *http.Client // contains filtered or unexported fields }
func (*ApiClient) GetTransPort ¶
func (*ApiClient) HttpPostJson ¶
func (client *ApiClient) HttpPostJson(ctx *gin.Context, path string, opts HttpRequestOptions) (*ApiResult, error)
deprecated , use HttpPost instead
type DefaultRender ¶
type DefaultRender struct { ErrNo int `json:"errNo"` ErrMsg string `json:"errMsg"` Data interface{} `json:"data"` }
default render
type ElasticClientConfig ¶
type ElasticClientConfig struct { Addr string `yaml:"addr"` Service string `yaml:"service"` Username string `yaml:"username"` Password string `yaml:"password"` Sniff bool `yaml:"sniff"` HealthCheck bool `yaml:"healthCheck"` Gzip bool `yaml:"gzip"` Decoder elastic.Decoder RetryStrategy elastic.Retrier HttpClient *http.Client Other []elastic.ClientOptionFunc }
type HttpRequestOptions ¶
type HttpRequestOptions struct { // 通用请求体,可通过Encode来对body做编码 RequestBody interface{} // 针对 RequestBody 的编码 Encode string // 老的请求data,httpGet / httPost 仍支持 Data map[string]string // httpPostJson 参数 JsonBody interface{} // 请求头指定 Headers map[string]string // cookie 设定 Cookies map[string]string /* httpGet / httPost 默认 application/x-www-form-urlencoded httpPostJson 默认 application/json */ BodyType string // 重试策略,可不指定,默认使用`defaultRetryPolicy`(只有在`api.yaml`中指定retry>0 时生效) RetryPolicy RetryPolicy // 重试间隔机制,可不指定,默认使用`defaultBackOffPolicy`(只有在`api.yaml`中指定retry>0 时生效) BackOffPolicy BackOffPolicy }
func (*HttpRequestOptions) GetBackOffPolicy ¶
func (o *HttpRequestOptions) GetBackOffPolicy() BackOffPolicy
func (*HttpRequestOptions) GetContentType ¶
func (o *HttpRequestOptions) GetContentType() (cType string)
func (*HttpRequestOptions) GetData ¶
func (o *HttpRequestOptions) GetData() (string, error)
func (*HttpRequestOptions) GetJsonData ¶
func (o *HttpRequestOptions) GetJsonData() (string, error)
func (*HttpRequestOptions) GetRequestData ¶
func (o *HttpRequestOptions) GetRequestData() (encodeData string, err error)
func (*HttpRequestOptions) GetRetryPolicy ¶
func (o *HttpRequestOptions) GetRetryPolicy() RetryPolicy
func (*HttpRequestOptions) GetUrlData ¶
func (o *HttpRequestOptions) GetUrlData() (string, error)
type MysqlConf ¶
type MysqlConf struct { Service string `yaml:"service"` DataBase string `yaml:"database"` Addr string `yaml:"addr"` User string `yaml:"user"` Password string `yaml:"password"` Charset string `yaml:"charset"` MaxIdleConns int `yaml:"maxidleconns"` MaxOpenConns int `yaml:"maxopenconns"` ConnMaxLifeTime time.Duration `yaml:"connMaxLifeTime"` ConnTimeOut time.Duration `yaml:"connTimeOut"` WriteTimeOut time.Duration `yaml:"writeTimeOut"` ReadTimeOut time.Duration `yaml:"readTimeOut"` }
type PprofConfig ¶
type PprofConfig struct {
Enable bool `yaml:"enable"`
}
type RedisClient ¶
func InitRedisClient ¶
func InitRedisClient(conf RedisConf) *RedisClient
deprecated use golib/redis.InitRedisClient() instead
type RedisConf ¶
type RedisConf struct { Service string `yaml:"service"` Addr string `yaml:"addr"` Password string `yaml:"password"` MaxIdle int `yaml:"maxIdle"` MaxActive int `yaml:"maxActive"` IdleTimeout time.Duration `yaml:"idleTimeout"` ConnTimeOut time.Duration `yaml:"connTimeOut"` ReadTimeOut time.Duration `yaml:"readTimeOut"` WriteTimeOut time.Duration `yaml:"writeTimeOut"` }
deprecated use golib/redis.Conf instead
Click to show internal directories.
Click to hide internal directories.