Documentation
¶
Index ¶
- func Get(r *http.Request, key string) any
- func GetListenAddress(r *http.Request) string
- func HTTPError(code int, f any, a ...any) error
- func Handler(handler any, permFuncs ...func(*http.Request) bool) http.Handler
- func HandlerWS(handler func(*http.Request, *Conn), handlerOther any) http.Handler
- func Output(w http.ResponseWriter, output any)
- func Set(r *http.Request, key string, value any) *http.Request
- type Client
- func (c *Client) Delete(url string, dest any) error
- func (c *Client) DisallowUnknownFields() *Client
- func (c *Client) Get(url string, dest any) error
- func (c *Client) Post(url string, data any, dest any) error
- func (c *Client) Put(url string, data any, dest any) error
- func (c *Client) Request(method, URL string, data any, dest any) error
- func (c *Client) WithHeaderToken(ht string) *Client
- func (c *Client) WithParamToken(pt string) *Client
- func (c *Client) WithToken(tk string) *Client
- func (c *Client) WithTokenPrefix(tp string) *Client
- func (c *Client) WithUnixSocket(socket string) *Client
- type Conn
- type HTTPStatus
- type Server
- func (s *Server) AddMiddleware(f func(next http.Handler) http.Handler)
- func (s *Server) Get(key string) any
- func (s *Server) Handle(pattern string, handler any, permFuncs ...func(*http.Request) bool)
- func (s *Server) Serve(addrs ...string) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Set(key string, value any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetListenAddress ¶ added in v0.0.9
GetListenAddress returns the address used by Serve in the execution of this Request.
func Handler ¶
Handler returns a http.Handler from a handler function.
handler must be a function with one of these signatures:
- http.Handler
- func (http.ResponseWriter, *http.Request)
- func [Input, Output any] (*http.Request, Input) (Output, error)
- func [Output any] (*http.Request) (Output, error)
If there are permFuncs, at least one of them must succeed.
If the error returned by the function implements HTTPStatus, it is used as the HTTP Status code to be returned.
func HandlerWS ¶ added in v0.0.8
HandlerWS returns a handler that tries to establish a Websocket connection, and calls handlerWS on success. If it does not success, and handlerOther is not nil, it uses that other handler.
func Output ¶ added in v0.0.9
func Output(w http.ResponseWriter, output any)
Output sends a JSON-encoded output.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a way to connect to 3rd party API servers.
func (*Client) DisallowUnknownFields ¶ added in v0.0.2
DisallowUnknownFields causes the JSON decoder to return an error when the destination is a struct and the input contains object keys which do not match any non-ignored, exported fields in the destination.
func (*Client) Request ¶
Request makes a HTTP request to the API. If data is not a []byte, it will be encoding as a JSON object.
func (*Client) WithHeaderToken ¶
WithHeaderToken specifies which Header line to use when sending a token.
func (*Client) WithParamToken ¶
WithParamToken specifies which query parameter to use when sending a token.
func (*Client) WithTokenPrefix ¶
WithTokenPrefix adds an optional prefix to the token in the Header line.
func (*Client) WithUnixSocket ¶ added in v0.0.6
WithUnixSocket causes the client to connect through this Unix domain socket, instead of using the network.
type Conn ¶ added in v0.0.8
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a Websocket connection.
type HTTPStatus ¶ added in v0.0.3
type HTTPStatus interface {
HTTPStatus() int
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP request multiplexer.
func (*Server) AddMiddleware ¶
AddMiddleware adds a new middleware to the Server. This should only be called before the first call to ServeHTTP.
func (*Server) Handle ¶
Handle registers a handler for one pattern in the server.
The function to be called when the server receives a petition matching the pattern will be Handler(handler, permFuncs...)
func (*Server) Serve ¶ added in v0.0.8
Serve accepts incoming connections on the specified address(es) and handles each connection in a goroutine.
The addresses can have the form "network!addr" or just "addr", in which case the network is inferred ("unix" if the addr is a filename beginning with "/", or "tcp" if the addr is "host:port").
Serve always returns a non-nil error.