Documentation ¶
Index ¶
- Constants
- func BindForm(req *http.Request, msg proto.Message) error
- func BindVars(req *http.Request, msg proto.Message) error
- func Do(client *http.Client, req *http.Request, target interface{}) error
- func NewClient(ctx context.Context, opts ...ClientOption) (*http.Client, error)
- func NewClientContext(ctx context.Context, info ClientInfo) context.Context
- func NewServerContext(ctx context.Context, info ServerInfo) context.Context
- func NewTransport(ctx context.Context, opts ...ClientOption) (http.RoundTripper, error)
- func StatusError(err error) (*errors.StatusError, int)
- func Vars(req *http.Request) map[string]string
- type ClientInfo
- type ClientOption
- type DecodeRequestFunc
- type EncodeErrorFunc
- type EncodeResponseFunc
- type MethodDesc
- type RouteGroup
- func (r *RouteGroup) ANY(path string, handler http.HandlerFunc)
- func (r *RouteGroup) DELETE(path string, handler http.HandlerFunc)
- func (r *RouteGroup) GET(path string, handler http.HandlerFunc)
- func (r *RouteGroup) HEAD(path string, handler http.HandlerFunc)
- func (r *RouteGroup) OPTIONS(path string, handler http.HandlerFunc)
- func (r *RouteGroup) PATCH(path string, handler http.HandlerFunc)
- func (r *RouteGroup) POST(path string, handler http.HandlerFunc)
- func (r *RouteGroup) PUT(path string, handler http.HandlerFunc)
- type Server
- func (s *Server) Endpoint() (string, error)
- func (s *Server) Handle(path string, h http.Handler)
- func (s *Server) HandleFunc(path string, h http.HandlerFunc)
- func (s *Server) RegisterService(desc *ServiceDesc, impl interface{})
- func (s *Server) RouteGroup(prefix string) *RouteGroup
- func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (s *Server) Start() error
- func (s *Server) Stop() error
- type ServerInfo
- type ServerOption
- type ServiceDesc
- type ServiceRegistrar
Constants ¶
const SupportPackageIsVersion1 = true
SupportPackageIsVersion1 These constants should not be referenced from any other code.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do send an HTTP request and decodes the body of response into target. returns an error (of type *Error) if the response status code is not 2xx.
func NewClientContext ¶
func NewClientContext(ctx context.Context, info ClientInfo) context.Context
NewClientContext returns a new Context that carries value.
func NewServerContext ¶
func NewServerContext(ctx context.Context, info ServerInfo) context.Context
NewServerContext returns a new Context that carries value.
func NewTransport ¶
func NewTransport(ctx context.Context, opts ...ClientOption) (http.RoundTripper, error)
NewTransport creates an http.RoundTripper.
func StatusError ¶
func StatusError(err error) (*errors.StatusError, int)
StatusError converts error to status error.
Types ¶
type ClientInfo ¶
ClientInfo is HTTP client infomation.
func FromClientContext ¶
func FromClientContext(ctx context.Context) (info ClientInfo, ok bool)
FromClientContext returns the Transport value stored in ctx, if any.
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption is HTTP client option.
func WithMiddleware ¶
func WithMiddleware(m middleware.Middleware) ClientOption
WithMiddleware with client middleware.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout with client request timeout.
func WithTransport ¶
func WithTransport(trans http.RoundTripper) ClientOption
WithTransport with client transport.
func WithUserAgent ¶
func WithUserAgent(ua string) ClientOption
WithUserAgent with client user agent.
type DecodeRequestFunc ¶
DecodeRequestFunc deocder request func.
type EncodeErrorFunc ¶
type EncodeErrorFunc func(res http.ResponseWriter, req *http.Request, err error)
EncodeErrorFunc is encode error func.
type EncodeResponseFunc ¶
type EncodeResponseFunc func(res http.ResponseWriter, req *http.Request, v interface{}) error
EncodeResponseFunc is encode response func.
type MethodDesc ¶
MethodDesc represents a Proto service's method specification.
type RouteGroup ¶
type RouteGroup struct {
// contains filtered or unexported fields
}
RouteGroup adds a matcher for the URL path and method. This matches if the given template is a prefix of the full URL path. See route.Path() for details on the tpl argument.
func (*RouteGroup) ANY ¶
func (r *RouteGroup) ANY(path string, handler http.HandlerFunc)
ANY maps an HTTP Any request to the path and the specified handler.
func (*RouteGroup) DELETE ¶
func (r *RouteGroup) DELETE(path string, handler http.HandlerFunc)
DELETE maps an HTTP Delete request to the path and the specified handler.
func (*RouteGroup) GET ¶
func (r *RouteGroup) GET(path string, handler http.HandlerFunc)
GET maps an HTTP Get request to the path and the specified handler.
func (*RouteGroup) HEAD ¶
func (r *RouteGroup) HEAD(path string, handler http.HandlerFunc)
HEAD maps an HTTP Head request to the path and the specified handler.
func (*RouteGroup) OPTIONS ¶
func (r *RouteGroup) OPTIONS(path string, handler http.HandlerFunc)
OPTIONS maps an HTTP Options request to the path and the specified handler.
func (*RouteGroup) PATCH ¶
func (r *RouteGroup) PATCH(path string, handler http.HandlerFunc)
PATCH maps an HTTP Patch request to the path and the specified handler.
func (*RouteGroup) POST ¶
func (r *RouteGroup) POST(path string, handler http.HandlerFunc)
POST maps an HTTP Post request to the path and the specified handler.
func (*RouteGroup) PUT ¶
func (r *RouteGroup) PUT(path string, handler http.HandlerFunc)
PUT maps an HTTP Put request to the path and the specified handler.
type Server ¶
Server is a HTTP server wrapper.
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
NewServer creates a HTTP server by options.
func (*Server) Endpoint ¶
Endpoint return a real address to registry endpoint. examples:
http://127.0.0.1:8000?isSecure=false
func (*Server) HandleFunc ¶
func (s *Server) HandleFunc(path string, h http.HandlerFunc)
HandleFunc registers a new route with a matcher for the URL path.
func (*Server) RegisterService ¶
func (s *Server) RegisterService(desc *ServiceDesc, impl interface{})
RegisterService .
type ServerInfo ¶
type ServerInfo struct { Request *http.Request Response http.ResponseWriter }
ServerInfo is HTTP server infomation.
func FromServerContext ¶
func FromServerContext(ctx context.Context) (info ServerInfo, ok bool)
FromServerContext returns the Transport value stored in ctx, if any.
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is HTTP server option.
func ErrorEncoder ¶
func ErrorEncoder(fn EncodeErrorFunc) ServerOption
ErrorEncoder with error handler option.
func Middleware ¶
func Middleware(m middleware.Middleware) ServerOption
Middleware with server middleware option.
type ServiceDesc ¶
type ServiceDesc struct { ServiceName string Methods []MethodDesc Metadata interface{} }
ServiceDesc represents a Proto service's specification.
type ServiceRegistrar ¶
type ServiceRegistrar interface {
RegisterService(desc *ServiceDesc, impl interface{})
}
ServiceRegistrar wraps a single method that supports service registration.