http

package
v0.0.0-...-26e1b9e Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOK           = xhttp.StatusOK
	StatusUnauthorized = xhttp.StatusUnauthorized
	AuthToken          = "AuthorizationToken"
)

Variables

View Source
var (
	ErrNoResponse = errors.New("请求未能得到接口返回信息!")

	DefaultClient = NewClient(&Config{})
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(config *Config) *Client

func (*Client) Get

func (c *Client) Get(ctx context.Context, uri string, params interface{}, res interface{}, opts ...Option) error

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, uri string, params interface{}, res interface{}, options Options) (err error)

func (*Client) Post

func (c *Client) Post(ctx context.Context, uri string, params interface{}, res interface{}, opts ...Option) error

type Config

type Config struct {
	CaCertPath          string        `json:"caCertPath" yaml:"caCertPath"` //启动https客户端的ca证书位置
	Timeout             time.Duration `json:"timeout" yaml:"timeout"`
	KeepAlive           time.Duration `json:"keepAlive" yaml:"keepAlive"`
	MaxIdleConns        int           `json:"maxIdleConns" yaml:"maxIdleConns"`
	MaxIdleConnsPerHost int           `json:"maxIdleConnsPerHost" yaml:"maxIdleConnsPerHost"`
	IdleConnTimeout     time.Duration `json:"idleConnTimeout" yaml:"idleConnTimeout"`
	Debug               bool          `json:"debug" yaml:"debug"`                 //是否打印调试日志
	DisableMetric       bool          `json:"disableMetric" yaml:"disableMetric"` //是否进行监控
	DisableTrace        bool          `json:"disableTrace" yaml:"disableTrace"`   //是否进行链路追踪
	SlowThreshold       time.Duration `json:"slowThreshold" yaml:"slowThreshold"`
}

func DefaultConfig

func DefaultConfig() Config

type Option

type Option func(o *Options)

func WithSysToken

func WithSysToken(caller, resource, requestId string) Option

func WithToken

func WithToken(token string) Option

type Options

type Options struct {
	Token string
}

Jump to

Keyboard shortcuts

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