Documentation ¶
Overview ¶
Package http implements a go-micro.Server
Index ¶
- Variables
- func 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 Middleware(mw ...func(http.Handler) http.Handler) server.Option
- func NewServer(opts ...server.Option) *httpServer
- func PathHandler(method, path string, handler http.HandlerFunc) server.Option
- func RegisterRPCHandler(b bool) server.Option
- func Server(hs *http.Server) server.Option
- func SetError(err interface{}) error
- func SetRspCode(ctx context.Context, code int)
- type Error
- type FillRequestOption
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.Errorf(ctx, "write failed: %v", cerr) } } DefaultContentType = "application/json" )
Functions ¶
func ErrorHandler ¶
func ErrorHandler(fn func(ctx context.Context, s server.Handler, w http.ResponseWriter, r *http.Request, err error, status int)) server.Option
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 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 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 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
Click to show internal directories.
Click to hide internal directories.