Documentation ¶
Index ¶
- Constants
- func GetCtxParam(c *gin.Context, key string) interface{}
- func GetCtxParamInt(c *gin.Context, key string) (i int)
- func GetCtxParamString(c *gin.Context, key string) (s string)
- func GetCtxParamTime(c *gin.Context, key string) (t time.Time)
- func HandlerAccessLog() gin.HandlerFunc
- func HandlerBizLog() gin.HandlerFunc
- func HandlerInitContext() gin.HandlerFunc
- func HandlerRecovery(stack bool) gin.HandlerFunc
- func LogAddCustomHeader(header string)
- func LogCritical(ctx context.Context, a interface{})
- func LogDebug(ctx context.Context, a interface{})
- func LogError(ctx context.Context, a interface{})
- func LogInfo(ctx context.Context, a interface{})
- func LogWarn(ctx context.Context, a interface{})
- type HttpClient
- func (cli *HttpClient) HttpGet(c *gin.Context, addr string, query map[string]string, ...) (string, error)
- func (cli *HttpClient) HttpOriginPost(c *gin.Context, addr string, query map[string]string, ...) (string, error)
- func (cli *HttpClient) JsonPost(c *gin.Context, addr string, query map[string]string, ...) (string, error)
- func (cli *HttpClient) MultipleJsonPost(c *gin.Context, addr string, params map[string]string, ...) (map[int]string, map[int]error)
- func (cli *HttpClient) ThirdFormGet(c *gin.Context, addr string, query map[string]string, ...) (string, error)
- func (cli *HttpClient) ThirdFormPost(c *gin.Context, addr string, query map[string]string, ...) (string, error)
- type HttpResponse
- type LogConfig
- type LogExtra
- type Logger
Constants ¶
View Source
const ( CtxRequestStart = "bw_request_start" // 请求开始时间 CtxRequestSize = "bw_request_size" // 请求大小 CtxRequestBody = "bw_request_body" // 请求Body )
请求上下文
View Source
const ( LogRequestMaxSize = 1024 LogResponseMaxSize = 1024 )
日志记录请求响应数据大小上限,太长影响性能
View Source
const ( LogValueDepartment = "bw" LogValueVersion = "bw-go-1.0" LogValueExtra = "{\"app\":\"default\",\"env\":\"default\",\"mode\":\"default\"}" )
日志字段默认值
View Source
const (
HttpHeaderTraceId = "Trace-ID"
)
Http Header
Variables ¶
This section is empty.
Functions ¶
func GetCtxParam ¶
func HandlerInitContext ¶
func HandlerInitContext() gin.HandlerFunc
初始化注入上下文参数 gin.Context.Keys类型是map,不保证线程安全 在多个goroutine共享,存在冲突的风险 https://github.com/gin-gonic/gin/issues/700 如果context需要在多个goroutine共享,使用context.Copy() 【备注】新的版本已通过读写锁 RWMutex 解决了这个问题
func LogAddCustomHeader ¶
func LogAddCustomHeader(header string)
func LogCritical ¶
Types ¶
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpClient ¶
func NewHttpClient(t time.Duration) *HttpClient
func (*HttpClient) HttpOriginPost ¶
func (*HttpClient) MultipleJsonPost ¶
func (cli *HttpClient) MultipleJsonPost(c *gin.Context, addr string, params map[string]string, headers map[string]string, bodyList map[int]interface{}) (map[int]string, map[int]error)
并发请求
func (*HttpClient) ThirdFormGet ¶
type HttpResponse ¶
type HttpResponse struct { ErrCode int `json:"error_code"` Message string `json:"message"` Result interface{} `json:"result"` }
func NewHttpResponse ¶
func NewHttpResponse(code int, message, result interface{}) *HttpResponse
Source Files ¶
Click to show internal directories.
Click to hide internal directories.