Documentation ¶
Index ¶
Constants ¶
const ( // StatusOk means that command was successfully processed. StatusOk = 0 // StatusErr means that command was not processed, // please check the `Response.Error` for details. StatusErr = 13 // StatusInternalErr means than command was not sent or decoding of response failed. StatusInternalErr = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { Name string Handler ActionFunc }
Action is a pair of command name and command handler.
type ActionFunc ¶
ActionFunc is a specified handler of the socket command.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides the ability to communicate over the socket with some application running `Server`.
type Request ¶
type Request struct { Action string `json:"ActionFunc"` Args json.RawMessage `json:"args"` }
Request is a pair of command name and command arguments.
type Response ¶
type Response struct { Status int `json:"status"` Error string `json:"error,omitempty"` Data json.RawMessage `json:"data"` }
Response is the result of executing the command handler.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a handler that opens a `net.Socket` and accepts commands and writes responses in JSON format.
func NewServer ¶
NewServer creates a new server with some actions.
func (*Server) Errors ¶
Errors returns a channel with errors.
func (*Server) Serve ¶
Serve creates the UNIX socket and starts listening for incoming commands. When command accepted server tries to decode message into `Request`. In case when the server has the handler for `Request` command it executes and writes a response in JSON format to the socket.
func (*Server) SetHandler ¶
func (sw *Server) SetHandler(name string, action ActionFunc)
SetHandler adds new or replaces the command (action) handler.