http_client

package
v1.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XRequestId      = "x-request-id"
	XB3TraceId      = "x-b3-traceid"
	XB3SpanId       = "x-b3-spanid"
	XB3ParentSpanId = "x-b3-parentspanid"
	XB3Sampled      = "x-b3-sampled"
	XB3Flags        = "x-b3-flags"
	B3              = "b3"
	XOtSpanContext  = "x-ot-span-context"
)

Variables

View Source
var (
	Prefix  = "easy-"
	TraceId = Prefix + "traceid"
)

Functions

func AddInterceptors

func AddInterceptors(client *resty.Client, onBefore resty.RequestMiddleware, onAfter resty.ResponseMiddleware, onErr resty.ErrorHook)

func ClientIP

func ClientIP(r *http.Request) string

ClientIP 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func ClientPublicIP

func ClientPublicIP(r *http.Request) string

ClientPublicIP 尽最大努力实现获取客户端公网 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func HasLocalIP

func HasLocalIP(ip net.IP) bool

HasLocalIP 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高,详见:https://github.com/thinkeridea/go-extend/issues/2

func HasLocalIPddr

func HasLocalIPddr(ip string) bool

HasLocalIPddr 检测 IP 地址字符串是否是内网地址

func IP2Long

func IP2Long(ip net.IP) (uint, error)

IP2Long 把net.IP转为数值

func IPString2Long

func IPString2Long(ip string) (uint, error)

IPString2Long 把ip字符串转为数值

func Long2IP

func Long2IP(i uint) (net.IP, error)

Long2IP 把数值转为net.IP

func Long2IPString

func Long2IPString(i uint) (string, error)

Long2IPString 把数值转为ip字符串

func MapToQuery

func MapToQuery(params map[string]interface{}, urlEncode ...bool) (string, error)

编译http参数

func RemoteIP

func RemoteIP(r *http.Request) string

RemoteIP 通过 RemoteAddr 获取 IP 地址, 只是一个快速解析方法。

Types

type AliyunLog

type AliyunLog struct {
	// contains filtered or unexported fields
}

func NewAliyunLog

func NewAliyunLog(topic string) *AliyunLog

func (*AliyunLog) Info

func (l *AliyunLog) Info(obj *LogObject) error

使用阿里云日志需要提前调用sls.InitLog初始化

type GocoreLog

type GocoreLog struct {
}

func NewGocoreLog

func NewGocoreLog() *GocoreLog

func (*GocoreLog) Info

func (l *GocoreLog) Info(obj *LogObject) error

type HttpClient

type HttpClient struct {
	*resty.Client
	Request *resty.Request
	// contains filtered or unexported fields
}

func NewHttpClient

func NewHttpClient(c *http_client_config.Config) *HttpClient

func (*HttpClient) EnableMetricInterceptor

func (h *HttpClient) EnableMetricInterceptor(metricPathRewriter http_client_config.MetricPathRewriter)

func (*HttpClient) SetLog

func (h *HttpClient) SetLog(log Log) *HttpClient

func (*HttpClient) SetTrace

func (h *HttpClient) SetTrace(header interface{}) *HttpClient

type Log

type Log interface {
	Info(obj *LogObject) error
}

type LogObject

type LogObject struct {
	Url             string        `json:"url"`
	Method          string        `json:"method"`
	RequestHders    http.Header   `json:"request_headers"`
	RequestRawBody  interface{}   `json:"request_raw_body"`
	ResponseHeaders http.Header   `json:"response_headers"`
	ResponseBody    string        `json:"response_body"`
	StartTime       string        `json:"start_time"`
	Duration        time.Duration `json:"duration"`
	Status          int           `json:"status"`
}

type TraceHeader

type TraceHeader struct {
	HttpHeader http.Header
	GrpcMd     metadata.MD
}

func SetGrpc

func SetGrpc(ctx context.Context) *TraceHeader

func SetHeader

func SetHeader(header interface{}) *TraceHeader

func SetHttp

func SetHttp(header http.Header) *TraceHeader

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL