httpx

package
v0.0.0-...-38cdf9c Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 27 Imported by: 5

Documentation

Index

Constants

View Source
const (
	EnvPrintAllAccess = "VLIBX_HTTP_PRINT_ALL_ACCESS"
)
View Source
const UserKey = userKeyType("requestUser")

Variables

View Source
var (
	ErrNotFound            = errors.New("client.http.notFound")
	ErrUnauthorized        = errors.New("client.http.unauthorized")
	ErrForbidden           = errors.New("client.http.forbidden")
	ErrInternalServerError = errors.New("client.http.internalServerError")
	ErrBadRequest          = errors.New("client.http.badRequest")
	ErrOtherStatus         = errors.New("client.http.otherStatus")
	ErrInvalidResponse     = errors.New("client.http.invalidResponse")
	ErrClientError         = errors.New("client.http.clientError")
)
View Source
var (
	ErrHttpParam = errors.New("error.http.param")
)

Functions

func CreateClient

func CreateClient(ctx *cli.Context) (*Client, AuthData, error)

func DefaultTransport

func DefaultTransport() *http.Transport

func GetUser

func GetUser[T auth.User](gtx context.Context) T

func GetUserId

func GetUserId(etx echo.Context) string

func MustGetUser

func MustGetUser(etx echo.Context) auth.User

func SendJSON

func SendJSON(etx echo.Context, data interface{}) error

func StrMsg

func StrMsg(err *echo.HTTPError) string

func WithClientFlags

func WithClientFlags(
	withAuth bool,
	envPrefix string,
	flags ...cli.Flag) []cli.Flag

Types

type ApiResult

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

func (*ApiResult) Close

func (ar *ApiResult) Close() error

func (*ApiResult) Error

func (ar *ApiResult) Error() error

func (*ApiResult) LoadClose

func (ar *ApiResult) LoadClose(out interface{}) error

type AuthData

type AuthData map[string]interface{}

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

func New

func New(address, contextRoot string) *Client

func NewCustom

func NewCustom(
	address, contextRoot string,
	transport *http.Transport,
	timeout time.Duration) *Client

func (*Client) Delete

func (client *Client) Delete(
	gtx context.Context,
	urlArgs ...string) *ApiResult

Delete - performs a delete request

func (*Client) Get

func (client *Client) Get(gtx context.Context, urlArgs ...string) *ApiResult

func (*Client) Post

func (client *Client) Post(
	gtx context.Context,
	content interface{},
	urlArgs ...string) *ApiResult

func (*Client) Put

func (client *Client) Put(
	gtx context.Context,
	content interface{},
	urlArgs ...string) *ApiResult

Put - performs a put request

func (*Client) RemoteHost

func (client *Client) RemoteHost() (string, error)

func (*Client) SetToken

func (client *Client) SetToken(token string) *Client

func (*Client) SetUser

func (client *Client) SetUser(user auth.User) *Client

func (*Client) User

func (client *Client) User() auth.User

type Endpoint

type Endpoint struct {
	Method      string
	Path        string
	Category    string
	Desc        string
	Version     string
	Role        auth.Role
	Permissions []string
	Route       *echo.Route
	Handler     echo.HandlerFunc
}

func MustGetEndpoint

func MustGetEndpoint(etx echo.Context) *Endpoint

func (*Endpoint) NeedsAuth

func (ep *Endpoint) NeedsAuth() bool

type ParamGetter

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

func NewParamGetter

func NewParamGetter(etx echo.Context) *ParamGetter

func (*ParamGetter) BadReqError

func (pm *ParamGetter) BadReqError() error

func (*ParamGetter) Bool

func (pm *ParamGetter) Bool(name string) bool

func (*ParamGetter) Error

func (pm *ParamGetter) Error() error

func (*ParamGetter) Float64

func (pm *ParamGetter) Float64(name string) float64

func (*ParamGetter) HasError

func (pm *ParamGetter) HasError() bool

func (*ParamGetter) Int

func (pm *ParamGetter) Int(name string) int

func (*ParamGetter) Int64

func (pm *ParamGetter) Int64(name string) int64

func (*ParamGetter) QueryBool

func (pm *ParamGetter) QueryBool(name string) bool

func (*ParamGetter) QueryBoolOr

func (pm *ParamGetter) QueryBoolOr(name string, def bool) bool

func (*ParamGetter) QueryFloat64

func (pm *ParamGetter) QueryFloat64(name string) float64

func (*ParamGetter) QueryFloat64Or

func (pm *ParamGetter) QueryFloat64Or(name string, def float64) float64

func (*ParamGetter) QueryInt

func (pm *ParamGetter) QueryInt(name string) int

func (*ParamGetter) QueryInt64

func (pm *ParamGetter) QueryInt64(name string) int64

func (*ParamGetter) QueryInt64Or

func (pm *ParamGetter) QueryInt64Or(name string, def int64) int64

func (*ParamGetter) QueryIntOr

func (pm *ParamGetter) QueryIntOr(name string, def int) int

func (*ParamGetter) QueryJSON

func (pm *ParamGetter) QueryJSON(name string, out interface{}) *ParamGetter

func (*ParamGetter) QueryStr

func (pm *ParamGetter) QueryStr(name string) string

func (*ParamGetter) QueryStrOr

func (pm *ParamGetter) QueryStrOr(name, def string) string

func (*ParamGetter) QueryUInt

func (pm *ParamGetter) QueryUInt(name string) uint

func (*ParamGetter) QueryUInt64Or

func (pm *ParamGetter) QueryUInt64Or(name string, def uint64) uint64

func (*ParamGetter) QueryUInt64Param

func (pm *ParamGetter) QueryUInt64Param(name string) uint64

func (*ParamGetter) QueryUIntOr

func (pm *ParamGetter) QueryUIntOr(name string, def uint) uint

func (*ParamGetter) Str

func (pm *ParamGetter) Str(name string) string

func (*ParamGetter) UInt

func (pm *ParamGetter) UInt(name string) uint

func (*ParamGetter) UInt64

func (pm *ParamGetter) UInt64(name string) uint64

func (*ParamGetter) WriteDetailedError

func (pm *ParamGetter) WriteDetailedError(w io.Writer)

type Server

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

func NewServer

func NewServer(printer io.Writer, userGetter auth.UserRetriever) *Server

func (*Server) Close

func (s *Server) Close() error

func (*Server) Print

func (s *Server) Print()

func (*Server) Start

func (s *Server) Start(port uint32) error

func (*Server) WithAPIs

func (s *Server) WithAPIs(ep ...*Endpoint) *Server

func (*Server) WithPages

func (s *Server) WithPages(ep ...*Endpoint) *Server

Jump to

Keyboard shortcuts

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