Documentation ¶
Overview ¶
Package service provides standardized command and HTTP setup by smartly composing the other cmdutil packages based on environment variables.
Index ¶
- func GRPC(l logrus.FieldLogger, m metrics.Provider, server grpcserver.Starter, ...) cmdutil.Server
- func HTTP(l logrus.FieldLogger, m metrics.Provider, h http.Handler, ...) cmdutil.Server
- func SkipEnforceHTTPS() func(*httpOptions)
- func WithHTTPServerHook(fn func(*http.Server)) func(*httpOptions)
- func WithTLSConfig(tlscfg *tls.Config) func(*httpOptions)
- type OptionFunc
- type Standard
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GRPC ¶
func GRPC( l logrus.FieldLogger, m metrics.Provider, server grpcserver.Starter, grpcOpts ...grpcserver.ServerOption) cmdutil.Server
GRPC returns a standard GRPC server for the provided handler. Router-bypass and TLS config are inferred from the environment.
Currently only supports running in router-bypass mode, unlike HTTP.
func HTTP ¶
func HTTP(l logrus.FieldLogger, m metrics.Provider, h http.Handler, opts ...func(*httpOptions)) cmdutil.Server
HTTP returns a standard HTTP server for the provided handler. Port, TLS, and router-bypass config are inferred from the environment.
func SkipEnforceHTTPS ¶
func SkipEnforceHTTPS() func(*httpOptions)
SkipEnforceHTTPS allows services to opt-out of SSL enforcement required for productionization. It should only be used in environments where SSL is not available.
func WithHTTPServerHook ¶ added in v0.0.17
WithHTTPServerHook allows services to provide a function to adjust settings on any HTTP server before after the defaults are applied but before the server is started.
Example ¶
package main import ( "io" "net/http" "time" "github.com/heroku/x/cmdutil/service" ) func main() { var cfg struct { Hello string `env:"HELLO,default=hello"` } svc := service.New(&cfg) handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = io.WriteString(w, cfg.Hello) }) configureHTTP := func(s *http.Server) { s.ReadTimeout = 10 * time.Second } svc.Add(service.HTTP(svc.Logger, svc.MetricsProvider, handler, service.WithHTTPServerHook(configureHTTP), )) svc.Run() }
Output:
func WithTLSConfig ¶
WithTLSConfig allows services to use a specific TLS configuration instead of the default one constructed from environment variables.
Types ¶
type OptionFunc ¶
type OptionFunc func(*options)
OptionFunc is a function that modifies internal service options.
func CustomMetricsSuffix ¶
func CustomMetricsSuffix(s string) OptionFunc
CustomMetricsSuffix to be added to metrics recorded by the MetricsProvider instead of inferring it from $DYNO.
func EnableOpenCensusTracing ¶ added in v0.0.12
func EnableOpenCensusTracing() OptionFunc
EnableOpenCensusTracing on the Service by registering and starting an open census agent exporter.
func SkipMetricsSuffix ¶
func SkipMetricsSuffix() OptionFunc
SkipMetricsSuffix prevents the Service from suffixing the process type to metric names recorded by the MetricsProvider. The default suffix is determined from $DYNO.
type Standard ¶
type Standard struct { App string Deploy string Logger logrus.FieldLogger MetricsProvider xmetrics.Provider // contains filtered or unexported fields }
Standard is a standard service.
func New ¶
func New(appConfig interface{}, ofs ...OptionFunc) *Standard
New Standard Service with logging, rollbar, metrics, debugging, common signal handling, and possibly more.
If appConfig is non-nil, envdecode.MustStrictDecode will be called on it to ensure that it is processed.