request

package
v1.9.14 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: MIT Imports: 20 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 FctHttpClient

type FctHttpClient func(def libtls.TLSConfig, servername string) *http.Client

type FctTLSDefault

type FctTLSDefault func() libtls.TLSConfig

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) GetClientHTTP

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

func (Options) New

func (Options) SetDefaultTLS

func (o Options) SetDefaultTLS(fct FctTLSDefault)

func (Options) Update

func (o Options) Update(req Request, ctx libcfg.FuncContext, cli FctHttpClient, tls FctTLSDefault) (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:"required,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"`
	Status   libsts.ConfigStatus `json:"status" yaml:"status" toml:"status" mapstructure:"status" validate:"required,dive"`
}

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 {
	Clone() (Request, error)
	New() (Request, error)

	GetOption() *Options
	SetOption(opt *Options) error
	SetClient(fct FctHttpClient)
	SetContext(fct libcfg.FuncContext)

	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)

	AuthBearer(token string)
	AuthBasic(user, pass string)
	ContentType(content string)

	CleanHeader()
	DelHeader(key string)
	SetHeader(key, value string)
	AddHeader(key, value string)

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

	Error() RequestError
	IsError() bool

	Do() (*http.Response, liberr.Error)
	DoParse(model interface{}, validStatus ...int) liberr.Error

	StatusRegister(sts libsts.RouteStatus, prefix string)
	StatusRegisterInfo(fct libsts.FctInfo)
}

func New

func New(ctx libcfg.FuncContext, cli FctHttpClient, opt Options) (Request, error)

type RequestError

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

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

	ParseBody(i interface{}) bool
}

Jump to

Keyboard shortcuts

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