Documentation ¶
Index ¶
- Constants
- Variables
- func ClientIp(r *http.Request) string
- func DeCode(s string) string
- func GetCmdOutsideIP() string
- func GetInsideIp(ctx context.Context) string
- func GetMacAddr(ctx context.Context) (arrays []string)
- func GetOutsideIPV4All(ctx context.Context) string
- func GetOutsideIPV6All(ctx context.Context) string
- func GetOutsideIp(ctx context.Context) string
- func GetParamsString(src interface{}) string
- func GetRandomUserAgent() string
- func GetRandomUserAgentSystem() string
- func GetRequestIDContext(ctx context.Context) string
- func IpIs(ipStr string) string
- func IpIsConsistent(ipStr1, ipStr2 string) bool
- func Ips(ctx context.Context) (map[string]string, error)
- func IsIPV4(s string) bool
- func IsIPV6(s string) bool
- func IsIPv4Public(ip net.IP) bool
- func IsIPv6Public(ip net.IP) bool
- func IsWechatMiniProgramRequest(r *http.Request, appid string) error
- func LenCode(s string) string
- func ParseQuery(s string) map[string][]string
- func SetRequestIDContext(ctx context.Context) context.Context
- func ToXml(params map[string]interface{}) (reader io.Reader, err error)
- func TraceEndSpan(span trace.Span)
- func TraceGetSpanID(ctx context.Context) (spanID string)
- func TraceGetTraceID(ctx context.Context) (traceID string)
- func TraceNewSpan(ctx context.Context, name string, spanName string, spanValue string, ...) (context.Context, trace.Span)
- func TraceRecordError(ctx context.Context, err error, options ...trace.EventOption)
- func TraceSetAttributes(ctx context.Context, kv ...attribute.KeyValue)
- func TraceSetStatus(ctx context.Context, code codes.Code, description string)
- func TraceSpanGetSpanID(span trace.Span) (spanID string)
- func TraceSpanGetTraceID(span trace.Span) (traceID string)
- func TraceSpanRecordError(span trace.Span, err error, options ...trace.EventOption)
- func TraceSpanSetAttributes(span trace.Span, kv ...attribute.KeyValue)
- func TraceSpanSetStatus(span trace.Span, code codes.Code, description string)
- func TraceStartSpan(ctx context.Context, spanName string) (context.Context, trace.Span)
- type App
- func (c *App) Connect(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (c *App) Delete(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (c *App) Get(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (c *App) Head(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (c *App) Options(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (c *App) Patch(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (c *App) Post(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (c *App) Put(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (c *App) Request(ctx context.Context) (httpResponse Response, err error)
- func (c *App) SetAuthToken(token string)
- func (c *App) SetClientIP(clientIP string)
- func (c *App) SetContentTypeForm()
- func (c *App) SetContentTypeJson()
- func (c *App) SetContentTypeXml()
- func (c *App) SetCookie(cookie string)
- func (c *App) SetHeader(key, value string)
- func (c *App) SetHeaders(headers Headers)
- func (c *App) SetLogFunc(logFunc LogFunc)
- func (c *App) SetMethod(method string)
- func (c *App) SetP12Cert(content *tls.Certificate)
- func (c *App) SetParam(key string, value interface{})
- func (c *App) SetParams(params Params)
- func (c *App) SetTlsVersion(minVersion, maxVersion uint16)
- func (c *App) SetTrace(trace bool)
- func (c *App) SetUri(uri string)
- func (c *App) SetUserAgent(ua string)
- func (c *App) Trace(ctx context.Context, uri ...string) (httpResponse Response, err error)
- type Headers
- type LogFunc
- type LogResponse
- type Params
- type Response
- func (r *Response) HeaderHtml() bool
- func (r *Response) HeaderIsImg() bool
- func (r *Response) HeaderIsJpeg() bool
- func (r *Response) HeaderIsJpg() bool
- func (r *Response) HeaderIsPng() bool
- func (r *Response) HeaderJson() bool
- func (r *Response) HeaderTextHtml() bool
- func (r *Response) HeaderXHtml() bool
- type ResponseUrlParse
- type UriParse
Constants ¶
const Version = "1.0.72"
Variables ¶
var (
TraceID = "trace-Id"
)
Functions ¶
func ClientIp ¶
ClientIp 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。
func GetMacAddr ¶ added in v1.0.40
GetMacAddr 获取Mac地址
func GetOutsideIPV4All ¶ added in v1.0.50
GetOutsideIPV4All 外网IPV4地址
func GetOutsideIPV6All ¶ added in v1.0.50
GetOutsideIPV6All 外网IPV6地址
func GetOutsideIp ¶ added in v1.0.40
GetOutsideIp 外网IP
func GetRandomUserAgentSystem ¶
func GetRandomUserAgentSystem() string
GetRandomUserAgentSystem 获取系统随机UA
func GetRequestIDContext ¶ added in v1.0.59
GetRequestIDContext 获取请求编号
func IpIsConsistent ¶ added in v1.0.67
IpIsConsistent 两个ip是否一致
func IsIPv4Public ¶ added in v1.0.50
func IsIPv6Public ¶ added in v1.0.50
func IsWechatMiniProgramRequest ¶ added in v1.0.39
IsWechatMiniProgramRequest 判断是否是微信小程序
func ParseQuery ¶ added in v1.0.19
ParseQuery 获取URL参数 https://studygolang.com/articles/2876
func SetRequestIDContext ¶ added in v1.0.65
SetRequestIDContext 设置请求编号
func TraceEndSpan ¶ added in v1.0.67
TraceEndSpan 结束OpenTelemetry链路追踪状态
func TraceGetSpanID ¶ added in v1.0.67
TraceGetSpanID 获取OpenTelemetry链路追踪SpanID
func TraceGetTraceID ¶ added in v1.0.67
TraceGetTraceID 获取OpenTelemetry链路追踪TraceID
func TraceNewSpan ¶ added in v1.0.67
func TraceNewSpan(ctx context.Context, name string, spanName string, spanValue string, version string, kind trace.SpanKind) (context.Context, trace.Span)
TraceNewSpan 创建OpenTelemetry链路追踪状态
func TraceRecordError ¶ added in v1.0.67
func TraceRecordError(ctx context.Context, err error, options ...trace.EventOption)
TraceRecordError 记录OpenTelemetry链路追踪错误
func TraceSetAttributes ¶ added in v1.0.67
TraceSetAttributes 设置OpenTelemetry链路追踪属性
func TraceSetStatus ¶ added in v1.0.67
TraceSetStatus 设置OpenTelemetry链路追踪状态
func TraceSpanGetSpanID ¶ added in v1.0.70
TraceSpanGetSpanID 获取OpenTelemetry链路追踪SpanID
func TraceSpanGetTraceID ¶ added in v1.0.70
TraceSpanGetTraceID 获取OpenTelemetry链路追踪TraceID
func TraceSpanRecordError ¶ added in v1.0.70
func TraceSpanRecordError(span trace.Span, err error, options ...trace.EventOption)
TraceSpanRecordError 记录OpenTelemetry链路追踪错误
func TraceSpanSetAttributes ¶ added in v1.0.70
TraceSpanSetAttributes 设置OpenTelemetry链路追踪属性
func TraceSpanSetStatus ¶ added in v1.0.70
TraceSpanSetStatus 设置OpenTelemetry链路追踪状态
Types ¶
type App ¶
type App struct { Uri string // 全局请求地址,没有设置url才会使用 // contains filtered or unexported fields }
App 实例
func (*App) SetClientIP ¶ added in v1.0.55
SetClientIP 设置客户端IP
func (*App) SetLogFunc ¶ added in v1.0.56
SetLogFunc 设置日志记录方法
func (*App) SetTlsVersion ¶ added in v1.0.39
SetTlsVersion 设置TLS版本
type LogFunc ¶ added in v1.0.55
type LogFunc func(ctx context.Context, response *LogResponse)
LogFunc 日志函数
type LogResponse ¶ added in v1.0.55
type LogResponse struct { TraceID string `json:"trace_id"` // 追踪编号 RequestID string `json:"request_id"` // 请求编号 RequestTime time.Time `json:"request_time"` // 请求时间 RequestUri string `json:"request_uri"` // 请求链接 RequestUrl string `json:"request_url"` // 请求链接 RequestApi string `json:"request_api"` // 请求接口 RequestMethod string `json:"request_method"` // 请求方式 RequestParams string `json:"request_params"` // 请求参数 RequestHeader string `json:"request_header"` // 请求头部 RequestIP string `json:"request_ip"` // 请求请求IP RequestCostTime int64 `json:"request_cost_time"` // 请求消耗时长 ResponseHeader string `json:"response_header"` // 返回头部 ResponseStatusCode int `json:"response_status_code"` // 返回状态码 ResponseBody string `json:"response_body"` // 返回Json数据 ResponseBodyJson string `json:"response_body_json"` // 返回Json数据 ResponseBodyXml string `json:"response_body_xml"` // 返回Xml数据 ResponseTime time.Time `json:"response_time"` // 返回时间 GoVersion string `json:"go_version"` // 程序GoVersion SdkVersion string `json:"sdk_version"` // 程序SdkVersion }
type Response ¶
type Response struct { RequestID string `json:"request_id"` // 请求编号 RequestUri string `json:"request_uri"` // 请求链接 RequestParams Params `json:"request_params"` // 请求参数 RequestMethod string `json:"request_method"` // 请求方式 RequestHeader Headers `json:"request_header"` // 请求头部 RequestCookie string `json:"request_cookie"` // 请求Cookie RequestTime time.Time `json:"request_time"` // 请求时间 RequestCostTime int64 `json:"request_cost_time"` // 请求消耗时长 ResponseHeader http.Header `json:"response_header"` // 响应头部 ResponseStatus string `json:"response_status"` // 响应状态 ResponseStatusCode int `json:"response_status_code"` // 响应状态码 ResponseBody []byte `json:"response_body"` // 响应内容 ResponseContentLength int64 `json:"response_content_length"` // 响应大小 ResponseTime time.Time `json:"response_time"` // 响应时间 }
Response 返回内容
func (*Response) HeaderHtml ¶ added in v1.0.28
HeaderHtml 判断是否为Html
func (*Response) HeaderIsImg ¶ added in v1.0.28
HeaderIsImg 判断是否为图片
func (*Response) HeaderIsJpeg ¶ added in v1.0.28
HeaderIsJpeg 判断是否为jpeg图片
func (*Response) HeaderIsJpg ¶ added in v1.0.28
HeaderIsJpg 判断是否为Jpg图片
func (*Response) HeaderIsPng ¶ added in v1.0.28
HeaderIsPng 判断是否为Png图片
func (*Response) HeaderJson ¶ added in v1.0.28
HeaderJson 判断是否为Json数据
func (*Response) HeaderTextHtml ¶ added in v1.0.28
HeaderTextHtml 判断是否为Html
func (*Response) HeaderXHtml ¶ added in v1.0.28
HeaderXHtml 判断是否为Html
type ResponseUrlParse ¶
type ResponseUrlParse struct { Uri string `json:"uri"` // URI Urn string `json:"urn"` // URN Url string `json:"url"` // URL Scheme string `json:"scheme"` // 协议 Host string `json:"host"` // 主机 Hostname string `json:"hostname"` // 主机名 Port string `json:"port"` // 端口 Path string `json:"path"` // 路径 RawQuery string `json:"raw_query"` // 参数 ? Fragment string `json:"fragment"` // 片段 # }
ResponseUrlParse 返回参数
type UriParse ¶
type UriParse struct {
// contains filtered or unexported fields
}
func (*UriParse) Parse ¶ added in v1.0.29
func (u *UriParse) Parse() (resp ResponseUrlParse)
Parse 解析URl
func (*UriParse) UriFilterExcludeQueryString ¶ added in v1.0.29
UriFilterExcludeQueryString 过滤掉url中的参数