Documentation ¶
Overview ¶
Middleware for handling CORS (cross origin requests) Warning: CORS requests needs to be whitelisted on ist.io ingress configuration Technically this middleware shouldn't be necessary but currently the ingress proxy forwards the CORS preflight request to the pod
Server infrastructure common for all microservices in the project. It contains the code that start and configures a HTTP and/or GRPC server correctly.
Setup implementation shared between all microservices. If this file is changed it will affect _all_ microservices in the monorepo (and this is deliberately so).
Setup implementation shared between all microservices. If this file is changed it will affect _all_ microservices in the monorepo (and this is deliberately so).
Index ¶
- func NewBasicAuthHandler(basicAuth *BasicAuth, chainedHandler http.Handler) http.Handler
- func Permanent(err error) error
- func Run(ctx context.Context, config ServerConfig)
- type BackgroundFunc
- type BackgroundTaskConfig
- type BasicAuth
- type BasicAuthHandler
- type CORSMiddleware
- type CORSPolicy
- type GRPCConfig
- type HTTPConfig
- type Health
- type HealthReporter
- type HealthServer
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBasicAuthHandler ¶
func Run ¶
func Run(ctx context.Context, config ServerConfig)
Types ¶
type BackgroundFunc ¶ added in v1.16.0
type BackgroundFunc func(context.Context, *HealthReporter) error
type BackgroundTaskConfig ¶
type BackgroundTaskConfig struct { // a function that triggers a graceful shutdown of all other resources after completion Run BackgroundFunc Name string // optional Shutdown func(context.Context) error }
type BasicAuthHandler ¶
type BasicAuthHandler struct {
// contains filtered or unexported fields
}
func (*BasicAuthHandler) ServeHTTP ¶
func (h *BasicAuthHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
type CORSMiddleware ¶
type CORSMiddleware struct { PolicyFor func(req *http.Request) *CORSPolicy NextHandler http.Handler }
func (*CORSMiddleware) ServeHTTP ¶
func (check *CORSMiddleware) ServeHTTP(rw http.ResponseWriter, req *http.Request)
type CORSPolicy ¶
type GRPCConfig ¶
type HTTPConfig ¶
type HealthReporter ¶ added in v1.16.0
type HealthReporter struct {
// contains filtered or unexported fields
}
func (*HealthReporter) ReportHealth ¶ added in v1.16.0
func (r *HealthReporter) ReportHealth(health Health, message string)
func (*HealthReporter) ReportHealthTtl ¶ added in v1.16.0
func (r *HealthReporter) ReportHealthTtl(health Health, message string, ttl *time.Duration) *time.Time
ReportHealthTtl returns the deadline (for testing)
func (*HealthReporter) ReportReady ¶ added in v1.16.0
func (r *HealthReporter) ReportReady(message string)
func (*HealthReporter) Retry ¶ added in v1.16.0
func (r *HealthReporter) Retry(ctx context.Context, fn func() error) error
Retry allows background services to set up reliable streaming with backoff.
This can be used to create background tasks that look like this:
func Consume(ctx context.Context, hr *setup.HealthReporter) error { state := initState() return hr.Retry(ctx, func() error { stream, err := startConsumer() if err != nil { return err } hr.ReportReady("receiving") for { select { case <-ctx.Done(): return nil case ev := <-stream: handleEvent(state, event) } } }) }
In the example above, connecting to the consumer will be retried a few times with backoff. The number of retries is reset whenever ReportReady is called so that successful connection heal the service.
type HealthServer ¶ added in v1.16.0
type HealthServer struct { BackOffFactory func() backoff.BackOff Clock func() time.Time // contains filtered or unexported fields }
func (*HealthServer) IsReady ¶ added in v1.16.0
func (h *HealthServer) IsReady(name string) bool
func (*HealthServer) Reporter ¶ added in v1.16.0
func (h *HealthServer) Reporter(name string) *HealthReporter
func (*HealthServer) ServeHTTP ¶ added in v1.16.0
func (h *HealthServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ServerConfig ¶ added in v1.16.0
type ServerConfig struct { GRPC *GRPCConfig HTTP []HTTPConfig // BackgroundTasks are tasks that are running forever, like Pub/sub receiver. If they // finish, a graceful shutdown will be triggered. Background []BackgroundTaskConfig Shutdown func(context.Context) error }
Config contains configurations for all servers & tasks will be started. A startup order is not guaranteed.