Documentation ¶
Overview ¶
Package http implements a go-micro.Server
Index ¶
- Variables
- func ErrorHandler(fn errorHandler) server.Option
- func FillRequest(ctx context.Context, req interface{}, opts ...FillRequestOption) error
- func GetError(err interface{}) interface{}
- func GetRspCode(ctx context.Context) int
- func HTTPServer(hs *http.Server) server.Option
- func HandlerEndpoints(md []EndpointMetadata) server.HandlerOption
- func Middleware(mw ...func(http.Handler) http.Handler) server.Option
- func PathHandler(method, path string, handler http.HandlerFunc) server.Option
- func RegisterCORSHandler(b bool) server.HandlerOption
- func RegisterRPCHandler(b bool) server.Option
- func SetError(err interface{}) error
- func SetRspCode(ctx context.Context, code int)
- func SetRspHeader(ctx context.Context, h http.Header)
- type EndpointMetadata
- type Error
- type FillRequestOption
- type Server
- func (h *Server) Deregister() error
- func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
- func (h *Server) Handle(handler server.Handler) error
- func (h *Server) Health() bool
- func (h *Server) Init(opts ...server.Option) error
- func (h *Server) Live() bool
- func (h *Server) Name() string
- func (h *Server) NewHandler(handler interface{}, opts ...server.HandlerOption) server.Handler
- func (h *Server) NewSubscriber(topic string, handler interface{}, opts ...server.SubscriberOption) server.Subscriber
- func (h *Server) Options() server.Options
- func (h *Server) Ready() bool
- func (h *Server) Register() error
- func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *Server) Start() error
- func (h *Server) Stop() error
- func (h *Server) String() string
- func (h *Server) Subscribe(sb server.Subscriber) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( DefaultErrorHandler = func(ctx context.Context, s server.Handler, w http.ResponseWriter, r *http.Request, err error, status int) { w.WriteHeader(status) if _, cerr := w.Write([]byte(err.Error())); cerr != nil { logger.DefaultLogger.Error(ctx, "write error", cerr) } } DefaultContentType = "application/json" )
Functions ¶
func ErrorHandler ¶
ErrorHandler specifies handler for errors
func FillRequest ¶
func FillRequest(ctx context.Context, req interface{}, opts ...FillRequestOption) error
func GetRspCode ¶
GetRspCode used internally by generated http server handler
func HTTPServer ¶ added in v3.10.31
HTTPServer provide ability to pass *http.Server
func HandlerEndpoints ¶ added in v3.10.11
func HandlerEndpoints(md []EndpointMetadata) server.HandlerOption
func Middleware ¶
Middleware passes http middlewares
func PathHandler ¶
func PathHandler(method, path string, handler http.HandlerFunc) server.Option
PathHandler specifies http handler for path regexp
func RegisterCORSHandler ¶ added in v3.10.31
func RegisterCORSHandler(b bool) server.HandlerOption
RegisterCORSHandler registers cors endpoints with /ServiceName.ServiceEndpoint method POPTIONSOST
func RegisterRPCHandler ¶
RegisterRPCHandler registers compatibility endpoints with /ServiceName.ServiceEndpoint method POST
func SetRspCode ¶
SetRspCode saves response code in context, must be used by handler to specify http code
Types ¶
type EndpointMetadata ¶ added in v3.10.11
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error struct holds error
type FillRequestOption ¶
type FillRequestOption func(*handlerOptions)
func Cookie ¶
func Cookie(cookies ...string) FillRequestOption
func Header ¶
func Header(headers ...string) FillRequestOption
type Server ¶
func (*Server) Deregister ¶ added in v3.10.31
func (*Server) HTTPHandlerFunc ¶ added in v3.10.31
func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
func (*Server) NewHandler ¶ added in v3.10.31
func (h *Server) NewHandler(handler interface{}, opts ...server.HandlerOption) server.Handler
func (*Server) NewSubscriber ¶ added in v3.10.31
func (h *Server) NewSubscriber(topic string, handler interface{}, opts ...server.SubscriberOption) server.Subscriber
Source Files ¶
Click to show internal directories.
Click to hide internal directories.