http

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = Client{}

Functions

func ErrorCode

func ErrorCode(err error, def int) int

func NewRequest

func NewRequest(c ctx.C, method string, url string, body io.Reader) (*http.Request, error)

func TestAPI

func TestAPI[T Doable, UID any](c ctx.C, uid UID, obj T) error

TODO

Types

type Call

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

func (*Call) SetBody

func (this *Call) SetBody(b []byte)

func (*Call) Write

func (this *Call) Write(b []byte)

type CallHandler

type CallHandler struct {
	Path        string
	MaxLength   int           // default is 1Mb
	ReadTimeout time.Duration // how long to wait for the request to be completed default is 30s
	Handler     func(c ctx.C, call *Call) error
}

func (CallHandler) Register

func (this CallHandler) Register(s *Server)

type Client

type Client struct {
	BaseUrl *url.URL
	// contains filtered or unexported fields
}

TODO circuit breaker!

func (Client) API

func (this Client) API(c ctx.C, obj Doable) error

func (Client) Do

func (this Client) Do(r *http.Request) (*http.Response, error)

func (Client) Get

func (this Client) Get(c ctx.C, url string) ([]byte, error)

func (Client) Post

func (this Client) Post(c ctx.C, url string, body []byte) ([]byte, error)

type Doable

type Doable interface {
	Do(ctx.C) error
}

type Error

type Error struct {
	Code int
	Err  error
}

func NewErrorf

func NewErrorf(c ctx.C, code int, f string, args ...any) Error

func (Error) Error

func (this Error) Error() string

func (Error) Unwrap

func (this Error) Unwrap() error

type Server

type Server struct {

	// called when a request is done, by default it logs and generate metrics
	OnResponse func(Stat)
	// contains filtered or unexported fields
}

func NewServer

func NewServer(c ctx.C) *Server

func (*Server) HandleRequest

func (this *Server) HandleRequest(pattern string, f func(c ctx.C, in []byte, r *http.Request) ([]byte, error))

func (Server) Listen

func (this Server) Listen(c ctx.C, addr string) (net.Addr, error)

func (Server) Mux

func (this Server) Mux() *http.ServeMux

func (*Server) RegisterAPI

func (s *Server) RegisterAPI(c ctx.C, obj Doable) error

type Stat

type Stat struct {
	Method  string
	Path    string
	UA      string
	Code    int
	Elapsed time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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