httper

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetMethod     method = "GET"
	PostMethod    method = "POST"
	PutMethod     method = "PUT"
	DeleteMethod  method = "DELETE"
	OptionsMethod method = "OPTIONS"
	HeadMethod    method = "HEAD"
	TraceMethod   method = "TRACE"
	ConnectMethod method = "CONNECT"

	JsonType contentType = "application/json"
	XmlType  contentType = "application/xml"
	TextType contentType = "text/plain"
	HtmlType contentType = "text/html"
)
View Source
const (
	StatusContinue           = 100
	StatusSwitchingProtocols = 101
	StatusProcessing         = 102
	StatusEarlyHints         = 103

	StatusOK                   = 200
	StatusCreated              = 201
	StatusAccepted             = 202
	StatusNonAuthoritativeInfo = 203
	StatusNoContent            = 204
	StatusResetContent         = 205
	StatusPartialContent       = 206
	StatusMultiStatus          = 207
	StatusAlreadyReported      = 208
	StatusIMUsed               = 226

	StatusMultipleChoices  = 300
	StatusMovedPermanently = 301
	StatusFound            = 302
	StatusSeeOther         = 303
	StatusNotModified      = 304
	StatusUseProxy         = 305

	StatusTemporaryRedirect = 307
	StatusPermanentRedirect = 308

	StatusBadRequest                   = 400
	StatusUnauthorized                 = 401
	StatusPaymentRequired              = 402
	StatusForbidden                    = 403
	StatusNotFound                     = 404
	StatusMethodNotAllowed             = 405
	StatusNotAcceptable                = 406
	StatusProxyAuthRequired            = 407
	StatusRequestTimeout               = 408
	StatusConflict                     = 409
	StatusGone                         = 410
	StatusLengthRequired               = 411
	StatusPreconditionFailed           = 412
	StatusRequestEntityTooLarge        = 413
	StatusRequestURITooLong            = 414
	StatusUnsupportedMediaType         = 415
	StatusRequestedRangeNotSatisfiable = 416
	StatusExpectationFailed            = 417
	StatusTeapot                       = 418
	StatusMisdirectedRequest           = 421
	StatusUnprocessableEntity          = 422
	StatusLocked                       = 423
	StatusFailedDependency             = 424
	StatusTooEarly                     = 425
	StatusUpgradeRequired              = 426
	StatusPreconditionRequired         = 428
	StatusTooManyRequests              = 429
	StatusRequestHeaderFieldsTooLarge  = 431
	StatusUnavailableForLegalReasons   = 451

	StatusInternalServerError           = 500
	StatusNotImplemented                = 501
	StatusBadGateway                    = 502
	StatusServiceUnavailable            = 503
	StatusGatewayTimeout                = 504
	StatusHTTPVersionNotSupported       = 505
	StatusVariantAlsoNegotiates         = 506
	StatusInsufficientStorage           = 507
	StatusLoopDetected                  = 508
	StatusNotExtended                   = 510
	StatusNetworkAuthenticationRequired = 511
)

Variables

View Source
var DefaultClient = NewClient(&ClientCfg{Prefix: "", Timeout: 5 * time.Second})

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(cfg *ClientCfg) *Client

func (*Client) Do

func (c *Client) Do(req *Req) (*Resp, error)

func (*Client) Get

func (c *Client) Get(url string) (*Resp, error)

func (*Client) GetJson added in v1.0.22

func (c *Client) GetJson(url string, to interface{}) (*Resp, error)

func (*Client) PostWithJson

func (c *Client) PostWithJson(url string, data interface{}) (*Resp, error)

func (*Client) PostWithJsonBind

func (c *Client) PostWithJsonBind(url string, data interface{}, to interface{}) (*Resp, error)

type ClientCfg

type ClientCfg struct {
	Prefix  string        `yaml:"prefix" env:"HTTP_CLIENT_PREFIX" env-default:""`
	Timeout time.Duration `yaml:"timeout" env:"HTTP_CLIENT_TIMEOUT" env-default:"5s"`
}

type CookieCfg added in v1.0.13

type CookieCfg struct {
	Name     string `yaml:"name" env:"COOKIE_NAME"`
	Age      int    `yaml:"age" env:"COOKIE_AGE"`
	Path     string `yaml:"path" env:"COOKIE_PATH"`
	Host     string `yaml:"host" env:"COOKIE_HOST"`
	Secure   bool   `yaml:"secure" env:"COOKIE_SECURE"`
	HttpOnly bool   `yaml:"http_only" env:"COOKIE_HTTP_ONLY"`
}

type Params

type Params struct {
	Method method
	Url    string

	Body     interface{}
	ByteBody []byte

	Marshal     bool
	MarshalType contentType

	Unmarshal     bool
	UnmarshalTo   interface{}
	UnmarshalType contentType
}

type Req

type Req struct {
	NeedUnmarshal bool
	*http.Request
	// contains filtered or unexported fields
}

func NewReq

func NewReq(params *Params) (*Req, error)

func (*Req) Unmarshal

func (r *Req) Unmarshal(body []byte) error

type Resp

type Resp struct {
	ByteBody []byte
	*http.Response
}

func Do

func Do(req *Req) (*Resp, error)

func Get

func Get(url string) (*Resp, error)

func GetJson added in v1.0.22

func GetJson(url string, to interface{}) (*Resp, error)

func PostWithJson

func PostWithJson(url string, data interface{}) (*Resp, error)

func PostWithJsonBind

func PostWithJsonBind(url string, data interface{}, to interface{}) (*Resp, error)

type ServeMux

type ServeMux = http.ServeMux

type Server

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

func NewServer

func NewServer(cfg *ServerCfg, handler http.Handler) *Server

func (*Server) Notify

func (s *Server) Notify() <-chan error

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) Start

func (s *Server) Start()

type ServerCfg

type ServerCfg struct {
	Url             string        `yaml:"url"             env:"SERVER_URL"              env-default:":80"`
	ReadTimeout     time.Duration `yaml:"readTimeout"     env:"SERVER_READ_TIMEOUT"     env-default:"5s"`
	WriteTimeout    time.Duration `yaml:"writeTimeout"    env:"SERVER_WRITE_TIMEOUT"    env-default:"5s"`
	ShutdownTimeout time.Duration `yaml:"shutdownTimeout" env:"SERVER_SHUTDOWN_TIMEOUT" env-default:"5s"`
}

Config is type for server setup.

Jump to

Keyboard shortcuts

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