Documentation ¶
Overview ¶
Package communication handels the translation from http and json-text to type-safe golang code. Thus, the actual api-handler doesn't have to bother (un-)marshalling json and type-safety. A handler-function can be registered for a specific http-method using the provided functions with the given names (Get, Post, ...). These functions support different types of handler-functions. The raw type of those handler-functions is interface{}, since the required specifications can't be handled at compile-time in golang. The actual type-pattern is described in the type's documentation. When such a handler-function is registered, its type is asserted via reflection, so that type-safety is re-established right after startup. If the handler-function doesn't match the specified type-pattern the registering-function (Get, Post, ...) panics with ErrIllegalHandleFunc
Index ¶
- Variables
- func Delete(path string, handler HandleDeleteFunc)
- func Get(path string, handler HandleGetFunc)
- func Options(path string, handler HandleOptionsFunc)
- func Post(path string, handler HandlePostFunc)
- func Put(path string, handler HandlePutFunc)
- func Router() *mux.Router
- func Serve()
- func Stream(path string, handler HandleStreamFunc)
- type HandleDeleteFunc
- type HandleGetFunc
- type HandleOptionsFunc
- type HandlePostFunc
- type HandlePutFunc
- type HandleStreamFunc
- type ParameterMap
Constants ¶
This section is empty.
Variables ¶
var ErrIllegalHandleFunc = errors.New("the given handler does not meet the requirements of HandleFunc")
ErrIllegalHandleFunc is an error thrown, when a function is registered, that doesn't meet the requirements issued in the docs above the according HandleFunc-type
Functions ¶
func Delete ¶
func Delete(path string, handler HandleDeleteFunc)
Delete registers a handler for the http DELETE method
func Get ¶
func Get(path string, handler HandleGetFunc)
Get registers a handler for the http GET method
func Options ¶
func Options(path string, handler HandleOptionsFunc)
Options registers a handler for the http OPTIONS method
func Post ¶
func Post(path string, handler HandlePostFunc)
Post registers a handler for the http POST method
func Put ¶
func Put(path string, handler HandlePutFunc)
Put registers a handler for the http PUT method
func Router ¶
Router returns the router used in this package. This function should only be used by tests
func Stream ¶
func Stream(path string, handler HandleStreamFunc)
Stream registers a websocket Stream-handler. When a client requests such a Stream, a websocket-connection is established. It can be closed by ether client or server. The latter closes the connection automatically, when the underlying channel (provided by the handler via the streams.Stream interface) is closed. The server only sends the Stream's values, when requested. I.e. the client must send a JSON-encoded uint value, which represents the number of requested streams.Characters. The streams.Characters are sent in JSON format. The actual representation depends on the underlying streams.StreamSource and how it was initialized
Types ¶
type HandleDeleteFunc ¶
type HandleDeleteFunc interface{}
HandleDeleteFunc represents a handler-function for a DELETE request. It has the following signature:
func(request A, parameters ParameterMap) (status int, response B)
Where A/B may be anything json.Unmarshal/json.Marshal can handle
type HandleGetFunc ¶
type HandleGetFunc interface{}
HandleGetFunc represents a handler-function for a GET request. It has the following signature:
func(parameters ParameterMap) (status int, response A)
Where A may be anything json.Marshal can handle
type HandleOptionsFunc ¶
type HandleOptionsFunc interface{}
HandleOptionsFunc represents a handler-function for a OPTIONS request. It has the following signature:
func(parameters ParameterMap) (status int, response A)
Where A may be anything json.Marshal can handle
type HandlePostFunc ¶
type HandlePostFunc interface{}
HandlePostFunc represents a handler-function for a POST request. It has the following signature:
func(request A, parameters ParameterMap) (status int, response B)
Where A/B may be anything json.Unmarshal/json.Marshal can handle
type HandlePutFunc ¶
type HandlePutFunc interface{}
HandlePutFunc represents a handler-function for a PUT request. It has the following signature:
func(request A, parameters ParameterMap) (status int)
Where A may be anything json.Unmarshal can handle
type HandleStreamFunc ¶
HandleStreamFunc represents a handler-function for websocket connection. It is based on a http GET request. If status is not successful (starting with 2) requests are rejected
type ParameterMap ¶
ParameterMap contains the parameters of a http-request. The key is the parameter's name and the value its value