Documentation
¶
Overview ¶
Package http implements a go-micro.Server
Index ¶
- Variables
- func ErrorHandler(fn errorHandler) options.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) options.Option
- func HandlerEndpoints(md []EndpointMetadata) options.Option
- func Middleware(mw ...func(http.Handler) http.Handler) options.Option
- func PathHandler(method, path string, handler http.HandlerFunc) options.Option
- func RegisterRPCHandler(b bool) options.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 interface{}, opts ...options.Option) error
- func (h *Server) Init(opts ...options.Option) error
- func (h *Server) Name() string
- func (h *Server) Options() server.Options
- 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
Constants ¶
This section is empty.
Variables ¶
View Source
var ( DefaultErrorHandler = func(ctx context.Context, s interface{}, 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, fmt.Sprintf("write failed: %v", 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 v4.0.5
HTTPServer provide ability to pass *http.Server
func HandlerEndpoints ¶
func HandlerEndpoints(md []EndpointMetadata) options.Option
func Middleware ¶
Middleware passes http middlewares
func PathHandler ¶
func PathHandler(method, path string, handler http.HandlerFunc) options.Option
PathHandler specifies http handler for path regexp
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 ¶
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 v4.0.3
func (*Server) HTTPHandlerFunc ¶ added in v4.0.4
func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.