request

package
v1.10.10 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgRequest
	ErrorParamInvalid
	ErrorValidatorError
	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:"required,url"`
	HttpClient libhtc.Options `json:"http_client" yaml:"http_client" toml:"http_client" mapstructure:"http_client" validate:"required,dive"`
	Auth       OptionsAuth    `json:"auth" yaml:"auth" toml:"auth" mapstructure:"auth" validate:"required,dive"`
	Health     OptionsHealth  `json:"health" yaml:"health" toml:"health" mapstructure:"health" validate:"required,dive"`
	// contains filtered or unexported fields
}

func (*Options) ClientHTTP added in v1.10.0

func (o *Options) ClientHTTP(servername string) *http.Client

func (*Options) ClientHTTPTLS added in v1.10.0

func (o *Options) ClientHTTPTLS(tls libtls.TLSConfig, servername string) *http.Client

func (*Options) New

func (o *Options) New(ctx libctx.FuncContext) (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() liberr.Error

type OptionsAuth

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

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:"required,dive"`
	Result   OptionsHealthResult `json:"result" yaml:"result" toml:"result" mapstructure:"result" validate:"required,dive"`
	Monitor  moncfg.Config       `json:"monitor" yaml:"monitor" toml:"monitor" mapstructure:"monitor" validate:"required,dive"`
}

func (*OptionsHealth) Validate added in v1.10.2

func (o *OptionsHealth) Validate() liberr.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(fct libtls.FctHttpClient)
	RegisterDefaultLogger(fct liblog.FuncLog)
	RegisterContext(fct libctx.FuncContext)

	Error() Error
	IsError() bool

	Do() (*http.Response, liberr.Error)
	DoParse(model interface{}, validStatus ...int) liberr.Error
	DoParseRetry(retry int, model interface{}, validStatus ...int) liberr.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) (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