Documentation ¶
Index ¶
- Variables
- func WriteError(w http.ResponseWriter, status int, msg string)
- type Codec
- type CodecRequest
- type CompressionSelector
- type Encoder
- type EncoderSelector
- type Server
- func (s *Server) HasMethod(name string) bool
- func (s *Server) RegisterAfterFunc(fn interface{}) error
- func (s *Server) RegisterBeforeFunc(fn interface{}) error
- func (s *Server) RegisterCodec(codec Codec, contentType string)
- func (s *Server) RegisterService(receiver interface{}, name string) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) ServiceMap() map[string][]string
Constants ¶
This section is empty.
Variables ¶
var DefaultEncoder = &encoder{}
var DefaultEncoderSelector = &encoderSelector{}
Functions ¶
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, msg string)
WriteError, a helper function to write error message to ResponseWriter
Types ¶
type Codec ¶
type Codec interface {
NewRequest(*http.Request) CodecRequest
}
Codec creates a CodecRequest to process each request.
type CodecRequest ¶
type CodecRequest interface { // Reads the request and returns the RPC method name. Method() (string, error) // Reads the request filling the RPC method args. ReadRequest(interface{}) error // Writes the response using the RPC method reply. WriteResponse(http.ResponseWriter, interface{}) // Writes an error produced by the server. WriteError(w http.ResponseWriter, status int, err error) }
CodecRequest decodes a request and encodes a response using a specific serialization scheme.
type CompressionSelector ¶
type CompressionSelector struct { }
CompressionSelector generates the compressed http encoder.
type Encoder ¶
type Encoder interface {
Encode(w http.ResponseWriter) io.Writer
}
Encoder interface contains the encoder for http response. Eg. gzip, flate compressions.
type EncoderSelector ¶
EncoderSelector interface provides a way to select encoder using the http request. Typically people can use this to check HEADER of the request and figure out client capabilities. Eg. "Accept-Encoding" tells about supported compressions.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
serves registered services with registered codecs.
func NewServer ¶
NewServer returns a new RPC server. param ctx is non-nil, and used to restrict the context param for service registering
func (*Server) HasMethod ¶
HasMethod returns true if the given method is registered.
The method uses a dotted notation as in "Service.Method".
func (*Server) RegisterAfterFunc ¶
RegisterAfterFunc validate and add a func that will be executed after service call
func (*Server) RegisterBeforeFunc ¶
RegisterBeforeFunc validate and add a func that will be executed before service call
func (*Server) RegisterCodec ¶
RegisterCodec adds a new codec to the server.
Codecs are defined to process a given serialization scheme, e.g., JSON or XML. A codec is chosen based on the "Content-Type" header from the request, excluding the charset definition.
func (*Server) RegisterService ¶
RegisterService adds a new service to the server.
The name parameter is optional: if empty it will be inferred from the receiver type name.
Methods from the receiver will be extracted if these rules are satisfied:
- The receiver is exported (begins with an upper case letter) or local (defined in the package registering the service).
- The method name is exported.
- The method has three arguments: *[Context Type], *args, *reply.
- All three arguments are pointers.
- The second and third arguments are exported or local.
- The method has return type error.
All other methods are ignored.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP
func (*Server) ServiceMap ¶
return the map of names of services with its methods