request

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgRequest
	ErrorParamInvalid
	ErrorValidatorError
	ErrorInvalidBody
	ErrorCreateRequest
	ErrorSendRequest
	ErrorResponseInvalid
	ErrorResponseLoadBody
	ErrorResponseStatus
	ErrorResponseUnmarshall
	ErrorResponseContainsNotFound
	ErrorResponseNotContainsFound
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorization added in v1.10.0

type Authorization interface {
	AuthBearer(token string)
	AuthBasic(user, pass string)
}

type Body added in v1.10.0

type Body interface {
	BodyJson(body interface{}) error
	BodyReader(body io.Reader, contentType string)
}

type Error added in v1.10.0

type Error interface {
	StatusCode() int
	Status() string
	Body() *bytes.Buffer
	Error() error

	IsError() bool
	IsStatusError() bool
	IsBodyError() bool

	ParseBody(i interface{}) bool
}
type Header interface {
	SetHeader(key, value string)
	AddHeader(key, value string)
	DelHeader(key string)

	CleanHeader()
	ContentType(mime string)
}

type Options

type Options struct {
	Endpoint string        `json:"endpoint" yaml:"endpoint" toml:"endpoint" mapstructure:"endpoint" validate:"url"`
	Auth     OptionsAuth   `json:"auth" yaml:"auth" toml:"auth" mapstructure:"auth" validate:""`
	Health   OptionsHealth `json:"health" yaml:"health" toml:"health" mapstructure:"health" validate:""`
	// contains filtered or unexported fields
}

func (*Options) New

func (o *Options) New(ctx libctx.FuncContext, cli libhtc.HttpClient) (Request, error)

func (*Options) SetDefaultLog added in v1.10.0

func (o *Options) SetDefaultLog(fct liblog.FuncLog)

func (*Options) SetDefaultTLS

func (o *Options) SetDefaultTLS(fct libtls.FctTLSDefault)

func (*Options) Update

func (o *Options) Update(ctx libctx.FuncContext, req Request) (Request, error)

func (*Options) Validate

func (o *Options) Validate() error

type OptionsAuth

type OptionsAuth struct {
	Basic  OptionsCredentials `json:"basic" yaml:"basic" toml:"basic" mapstructure:"basic" validate:""`
	Bearer OptionsToken       `json:"bearer" yaml:"bearer" toml:"bearer" mapstructure:"bearer" validate:""`
}

type OptionsCredentials

type OptionsCredentials struct {
	Enable   bool   `json:"enable" yaml:"enable" toml:"enable" mapstructure:"enable"`
	Username string `json:"username" yaml:"username" toml:"username" mapstructure:"username"`
	Password string `json:"password" yaml:"password" toml:"password" mapstructure:"password"`
}

type OptionsHealth

type OptionsHealth struct {
	Enable   bool                `json:"enable" yaml:"enable" toml:"enable" mapstructure:"enable"`
	Endpoint string              `json:"endpoint" yaml:"endpoint" toml:"endpoint" mapstructure:"endpoint" validate:"url"`
	Auth     OptionsAuth         `json:"auth" yaml:"auth" toml:"auth" mapstructure:"auth" validate:""`
	Result   OptionsHealthResult `json:"result" yaml:"result" toml:"result" mapstructure:"result" validate:""`
	Monitor  moncfg.Config       `json:"monitor" yaml:"monitor" toml:"monitor" mapstructure:"monitor" validate:"required"`
}

func (*OptionsHealth) Validate added in v1.10.2

func (o *OptionsHealth) Validate() error

type OptionsHealthResult

type OptionsHealthResult struct {
	ValidHTTPCode   []int    `json:"valid_http_code" yaml:"valid_http_code" toml:"valid_http_code" mapstructure:"valid_http_code"`
	InvalidHTTPCode []int    `json:"invalid_http_code" yaml:"invalid_http_code" toml:"invalid_http_code" mapstructure:"invalid_http_code"`
	Contain         []string `json:"contain" yaml:"contain" toml:"contain" mapstructure:"contain"`
	NotContain      []string `json:"not_contain" yaml:"not_contain" toml:"not_contain" mapstructure:"not_contain"`
}

type OptionsToken

type OptionsToken struct {
	Enable bool   `json:"enable" yaml:"enable" toml:"enable" mapstructure:"enable"`
	Token  string `json:"token" yaml:"token" toml:"token" mapstructure:"token"`
}

type Request

type Request interface {
	Url
	Authorization
	Header
	Body

	Clone() (Request, error)
	New() (Request, error)

	GetOption() *Options
	SetOption(opt *Options) error
	RegisterHTTPClient(cli libhtc.HttpClient)
	RegisterDefaultLogger(fct liblog.FuncLog)
	RegisterContext(fct libctx.FuncContext)

	Error() Error
	IsError() bool

	Do() (*http.Response, error)
	DoParse(model interface{}, validStatus ...int) error
	DoParseRetry(retry int, model interface{}, validStatus ...int) error

	Monitor(ctx context.Context, vrs libver.Version) (montps.Monitor, error)
	HealthCheck(ctx context.Context) error
}

func New

func New(ctx libctx.FuncContext, opt *Options, cli libhtc.HttpClient) (Request, error)

type Url added in v1.10.0

type Url interface {
	SetEndpoint(u string) error
	GetEndpoint() string

	SetPath(raw bool, path string)
	AddPath(raw bool, path ...string)

	SetMethod(mtd string)
	GetMethod() string

	CleanParams()
	DelParams(key string)
	SetParams(key, val string)
	AddParams(key, val string)

	GetFullUrl() *url.URL
	SetFullUrl(u *url.URL)
}

Jump to

Keyboard shortcuts

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