Documentation ¶
Index ¶
- func ListenAndServe(ctx context.Context, addr string, srv *http.Server) error
- func MethodAndPathCleanID(r *http.Request) string
- func New(cfg *Config) (*http.Server, error)
- func PathWithCleanID(r *http.Request) string
- type Config
- type Option
- func WithCORS(allowedOrigins, allowedMethods, allowedHeaders []string, allowCredentials bool) Option
- func WithCORSWideOpen() Option
- func WithGRPC(srv *grpc.Server) Option
- func WithLogging(app string) Option
- func WithMetrics(app string, opNameFunc func(r *http.Request) string) Option
- func WithRecovery(writer io.Writer, printStack bool) Option
- func WithTracing(server, app string, tags map[string]string, ...) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe serves an http server over TCP
func MethodAndPathCleanID ¶
MethodAndPathCleanID replace string values that look like ids (uuids and int) with "*"
func New ¶
New creates a new http server
Example:
srv, _ := server.New(&server.Config{ Addr: ":8080", Handler: http.DefaultServeMux, Options: []server.Option{ server.WithLogging("my-server"), server.WithMetrics("my-server"), server.WithRecovery(), server.WithTracing("opentracing-server:6831", "my-server"), } })
srv.ListenAndServe(context.Background())
func PathWithCleanID ¶ added in v0.4.0
PathWithCleanID replace string values that look like ids (uuids and int) with "*"
Types ¶
type Option ¶
Option is the interface for all server options defined in this package
func WithCORS ¶
func WithCORS(allowedOrigins, allowedMethods, allowedHeaders []string, allowCredentials bool) Option
WithCORS configures CORS on the webserver
func WithCORSWideOpen ¶
func WithCORSWideOpen() Option
WithCORSWideOpen allows requests from all origins with all methods and all headers/cookies/credentials allowed.
func WithGRPC ¶
WithGRPC configures the webserver to serve grpc-web requests as specified in https://github.com/improbable-eng/grpc-web
func WithLogging ¶
WithLogging configures a logrus middleware for that server
func WithMetrics ¶
WithMetrics configures metrics collection
func WithRecovery ¶
WithRecovery configures panic recovery for that server