httpm

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodGet  = "GET"
	MethodPost = "POST"
	MethodPut  = "PUT"

	JsonHeader    = "application/json;charset=UTF-8"
	FormUrlHeader = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func CreateHTTPClient

func CreateHTTPClient(c config.HttpConf) *http.Client

CreateHTTPClient

func GenerateRequest

func GenerateRequest(ctx context.Context, method, url string, reqData any) (request *http.Request, err error)

func SetBasicAuth

func SetBasicAuth(username, password string) map[string]string

func SetBeautify

func SetBeautify(flag bool)

func SetBreaker

func SetBreaker(flag bool)

func SetDisableLogDetail

func SetDisableLogDetail(flag bool)

func SetHttpClient

func SetHttpClient(httpClient *http.Client)

func SetHttpConf

func SetHttpConf(httpConf config.HttpConf)

func SetLogDetail

func SetLogDetail(flag bool)

func SetMaxBodyLen

func SetMaxBodyLen(max int)

func SetPromConf

func SetPromConf(conf PromConf)

func SetSlowThreshold

func SetSlowThreshold(d int)

Types

type Option

type Option func(o *options)

func WithBreakerName

func WithBreakerName(name string) Option

func WithHeader

func WithHeader(header map[string]string) Option

func WithLabels

func WithLabels(labels []string) Option

func WithNeedDuration

func WithNeedDuration(flag bool) Option

func WithOnlyInterfaceDuration

func WithOnlyInterfaceDuration(flag bool) Option

func WithParseResp

func WithParseResp(respData any) Option

func WithParseRespBody

func WithParseRespBody(flag bool) Option

func WithRequest

func WithRequest(request *http.Request) Option

func WithTimeout

func WithTimeout(timeout int) Option

func WithTmpLogDetail

func WithTmpLogDetail(flag bool) Option

type PromConf

type PromConf struct {
	Enable bool   `json:"enable,optional" default:"false"`  // enable
	Host   string `json:"host,optional" default:"0.0.0.0"`  // host
	Port   int    `json:"port,optional" default:"9090"`     // port
	Path   string `json:"path,optional" default:"/metrics"` // path
}

type Response

type Response struct {
	Duration time.Duration `json:"duration"`
}

func Do

func Do(ctx context.Context, method, url string, reqData any, option ...Option) (result *Response, err error)

Jump to

Keyboard shortcuts

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