Documentation ¶
Overview ¶
Package rest contains helpers for rest clients and servers.
Index ¶
- Variables
- func Dir(useLocal bool, name string) http.FileSystem
- func FS(useLocal bool) http.FileSystem
- func FSByte(useLocal bool, name string) ([]byte, error)
- func FSMustByte(useLocal bool, name string) []byte
- func FSMustString(useLocal bool, name string) string
- func FSString(useLocal bool, name string) (string, error)
- func GoSendAll(okCode int, log func(string, ...interface{}), clients ...ClientRequest)
- func SendAll(okCode int, clients ...ClientRequest) error
- type Client
- type ClientRequest
- type ClientResponse
- type HTTPError
- type Mux
- type Request
Constants ¶
This section is empty.
Variables ¶
ErrRequest happens when a HTTP request is invalid.
Functions ¶
func Dir ¶
func Dir(useLocal bool, name string) http.FileSystem
Dir returns a http.Filesystem for the embedded assets on a given prefix dir. If useLocal is true, the filesystem's contents are instead used.
func FS ¶
func FS(useLocal bool) http.FileSystem
FS returns a http.Filesystem for the embedded assets. If useLocal is true, the filesystem's contents are instead used.
func FSByte ¶
FSByte returns the named file from the embedded assets. If useLocal is true, the filesystem's contents are instead used.
func FSMustByte ¶
FSMustByte is the same as FSByte, but panics if name is not present.
func FSMustString ¶
FSMustString is the string version of FSMustByte.
func FSString ¶
FSString is the string version of FSByte.
func GoSendAll ¶
func GoSendAll(okCode int, log func(string, ...interface{}), clients ...ClientRequest)
GoSendAll sends all ClientRequests. The log parameter is expected to have fmt.Printf like functionality and log errors somewhere is not nil.
func SendAll ¶
func SendAll(okCode int, clients ...ClientRequest) error
SendAll sends all ClientRequests and returns the error.
Types ¶
type Client ¶
type Client interface { // Request begins a new HTTP request. Request(ctx context.Context, url string, method string) ClientRequest // RoundTripper returns the used transport for the Client. RoundTripper() http.RoundTripper }
Client is an improved http client.
type ClientRequest ¶
type ClientRequest interface { // JSONBody includes a JSON string into a HTTP body request. JSONBody(data interface{}) ClientRequest // StringBody includes a string into a HTTP body request. StringBody(data string) ClientRequest // Header adds a header to the request. Header(key string, value ...string) ClientRequest // Send a request on its way. Send(okCode ...int) ClientResponse }
ClientRequest is an improved HTTP client request.
type ClientResponse ¶
type ClientResponse interface { // JSONBody extracts a JSON string from a HTTP body request. JSONBody(data interface{}) ClientResponse // ByteSliceBody extracts a byte slice from a HTTP body request. ByteSliceBody(data *[]byte) ClientResponse // StringBody extracts a string from a HTTP body request. StringBody(dst *string) ClientResponse // Check finalizes the request and returns an error on failure or unexpected status code. Check() error }
ClientResponse represents an received HTTP response.
type HTTPError ¶
HTTPError represents an HTTP error in combination with an HTTP status code.
type Mux ¶
type Mux interface { // Forward a path to some other host. Forward(client Client, path, host, redirect string) // AddDefaultResponseHeader to the given header. AddDefaultResponseHeader(header http.Header) // Endpoint provides a server end point for a rest application. The given handler is called on each invoction. Endpoint(path string, queryHandler func(query *Request)) // ServeHTTP just calls net/http.ServeMux.ServeHTTP. ServeHTTP(w http.ResponseWriter, r *http.Request) // Handle just calls net/http.ServeMux.Handle. Handle(pattern string, handler http.Handler) // HandleFunc just calls net/http.ServeMux.HandleFunc. HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) }
Mux is an http ServeMux with extra methods.