Documentation ¶
Index ¶
- func ParseUrl(url string) (*regexp.Regexp, []string)
- type Config
- type Response
- type Route
- func (r *Route) SetDeleteHandler(handler func(htp.Params) (interface{}, error)) *Route
- func (r *Route) SetGetHandler(handler func(htp.Params) (interface{}, error)) *Route
- func (r *Route) SetHandler(method string, handler interface{}) *Route
- func (r *Route) SetParams(method string, params ...string) *Route
- func (r *Route) SetPatchHandler(handler func(htp.Params) (interface{}, error)) *Route
- func (r *Route) SetPostHandler(handler func(data []byte) (interface{}, error)) *Route
- func (r *Route) SetPutHandler(handler func(htp.Params) (interface{}, error)) *Route
- type Server
- func (s *Server) RegisterAction(method, url string, handler interface{}) error
- func (s *Server) RegisterDeleteAction(url string, handler func(htp.Params) (interface{}, error)) error
- func (s *Server) RegisterGetAction(url string, handler func(htp.Params) (interface{}, error)) error
- func (s *Server) RegisterPatchAction(url string, handler func(htp.Params) (interface{}, error)) error
- func (s *Server) RegisterPostAction(url string, handler func([]byte) (interface{}, error)) error
- func (s *Server) RegisterPutAction(url string, handler func(htp.Params) (interface{}, error)) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (s *Server) Start() error
- func (s *Server) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Path string ServePort uint16 NetListen func(port uint16) (net.Listener, error) Response func(result interface{}, err error) []byte }
Config is the configuration of the RESTful server.
type Route ¶
type Route struct { GetHandler func(params htp.Params) (interface{}, error) PutHandler func(params htp.Params) (interface{}, error) PatchHandler func(params htp.Params) (interface{}, error) DeleteHandler func(params htp.Params) (interface{}, error) PostHandler func(data []byte) (interface{}, error) // contains filtered or unexported fields }
func (*Route) SetDeleteHandler ¶
func (*Route) SetGetHandler ¶
func (*Route) SetHandler ¶
func (*Route) SetPatchHandler ¶
func (*Route) SetPostHandler ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) RegisterAction ¶
RegisterAction register a RESTful handler with the given url and method. For a url with parameters, add /:param at the end of url like /api/block/:hash. multiple parameters are supported, like /api/account/:assetid/:address. The registered handler type must match the method, for example, GET method must use func(params http.Params) (interface{}, error) as handler.
func (*Server) RegisterDeleteAction ¶
func (s *Server) RegisterDeleteAction(url string, handler func(htp.Params) (interface{}, error)) error
RegisterDeleteAction register a RESTful handler with the given url.
func (*Server) RegisterGetAction ¶
RegisterGetAction register a RESTful handler with the given url.
func (*Server) RegisterPatchAction ¶
func (s *Server) RegisterPatchAction(url string, handler func(htp.Params) (interface{}, error)) error
RegisterPatchAction register a RESTful handler with the given url.
func (*Server) RegisterPostAction ¶
RegisterPostAction register a RESTful handler with the given url.
func (*Server) RegisterPutAction ¶
RegisterPutAction register a RESTful handler with the given url.