Documentation
¶
Index ¶
- type Handler
- type Params
- func (p Params) AsBool(key string) (bool, error)
- func (p Params) AsFloat32(key string) (float32, error)
- func (p Params) AsFloat64(key string) (float64, error)
- func (p Params) AsInt(key string) (int, error)
- func (p Params) AsString(key string) (string, error)
- func (p Params) SetBool(key string, val bool)
- func (p Params) SetFloat32(key string, val float32)
- func (p Params) SetFloat64(key string, val float64)
- func (p Params) SetInt(key string, val int)
- func (p Params) SetString(key, val string)
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
Handler is a function that takes a map of input parameters and returns a (possibly empty or nil) map of output parameters, as expected by a Diatheke command.
type Params ¶
Params is an alias for a map[string]string that includes some convenience functions for converting to other types. To create a new Params object, use the go standard make function (e.g., `make(Params)`). Note that the convenience functions are not safe to use concurrently (just as it is not safe to access a regular map in Go concurrently).
func (Params) AsBool ¶
AsBool returns the parameter value for the given key as a bool. Returns an error if the key was not found or there was a problem during conversion.
func (Params) AsFloat32 ¶
AsFloat32 returns the parameter value for the given key as a float32. Returns an error if the key was not found or there was problem during conversion.
func (Params) AsFloat64 ¶
AsFloat64 returns the parameter value for the given key as a float64. Returns an error if the key was not found or there was a problem during conversion.
func (Params) AsInt ¶
AsInt returns the parameter value for the given key as an int. Returns an error if the key was not found or there was a problem during conversion.
func (Params) AsString ¶
AsString returns the parameter value for the given key as a string. Returns an error if the key was not found. Note that the underlying map may be used directly to get the parameter and check it's existence without the error (e.g., `val, ok := p[key]`).
func (Params) SetBool ¶
SetBool converts the given bool to a string and stores it in the parameter map.
func (Params) SetFloat32 ¶
SetFloat32 converts the given float32 to a string and stores it in the parameter map. This uses the 'g' formatting style for the conversion, with a precision of 4. For different formatting, it is recommended to use strconv.FormatFloat().
func (Params) SetFloat64 ¶
SetFloat64 converts the given float64 to a string and stores it in the parameter map. This uses the 'g' formatting style for the conversion, with a precision of 4. For different formatting, it is recommended to use strconv.FormatFloat().
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an http server that handles Diatheke commands. With this server, all commands go to the same URL, so the Diatheke model should be set accordingly. Once received, commands are sent to Handlers added with the SetHandler function.
func (*Server) Run ¶
Run starts the http server and listens at the given address (e.g., ":8072", "localhost:1515", "127.0.0.1:3535") until either an error occurs or the interrupt signal is received.
func (*Server) ServeHTTP ¶
func (svr *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface. It decodes the command, forwards the data to the correct command Handler, then encodes the result to send back to Diatheke.
func (*Server) SetHandler ¶
SetHandler registers the provided Handler to be called for the specified command ID.