Documentation ¶
Overview ¶
TODO: it would be nice to move these into the top level folder so people can use these with the "functions" package, eg: functions.ApiHandler
Index ¶
- Constants
- Variables
- func HandleErrorResponse(ctx context.Context, w http.ResponseWriter, err error)
- func NewFnSpan(s opentracing.Span) opentracing.Span
- func NewFnTracer(t opentracing.Tracer) opentracing.Tracer
- func NewPrometheusCollector() (zipkintracer.Collector, error)
- type ApiAppHandler
- type ApiAppHandlerFunc
- type ApiHandler
- type ApiHandlerFunc
- type FnSpan
- type FnTracer
- type Middleware
- type MiddlewareFunc
- type PrometheusCollector
- type Server
- func (s *Server) AddAppEndpoint(method, path string, handler ApiAppHandler)
- func (s *Server) AddAppEndpointFunc(method, path string, ...)
- func (s *Server) AddAppListener(listener extensions.AppListener)
- func (s *Server) AddCallListener(listener extensions.CallListener)
- func (s *Server) AddEndpoint(method, path string, handler ApiHandler)
- func (s *Server) AddEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request))
- func (s *Server) AddMiddleware(m Middleware)
- func (s *Server) AddMiddlewareFunc(m MiddlewareFunc)
- func (s *Server) FireAfterAppCreate(ctx context.Context, app *models.App) error
- func (s *Server) FireAfterAppDelete(ctx context.Context, app *models.App) error
- func (s *Server) FireAfterAppUpdate(ctx context.Context, app *models.App) error
- func (s *Server) FireBeforeAppCreate(ctx context.Context, app *models.App) error
- func (s *Server) FireBeforeAppDelete(ctx context.Context, app *models.App) error
- func (s *Server) FireBeforeAppUpdate(ctx context.Context, app *models.App) error
- func (s *Server) Start(ctx context.Context)
- type ServerOption
Constants ¶
const ( EnvLogLevel = "log_level" EnvMQURL = "mq_url" EnvDBURL = "db_url" EnvLOGDBURL = "logstore_url" EnvPort = "port" // be careful, Gin expects this variable to be "port" EnvAPIURL = "api_url" EnvZipkinURL = "zipkin_url" )
Variables ¶
var ErrInternalServerError = errors.New("internal server error")
ErrInternalServerError returned when something exceptional happens.
Functions ¶
func HandleErrorResponse ¶
func HandleErrorResponse(ctx context.Context, w http.ResponseWriter, err error)
HandleErrorResponse used to handle response errors in the same way.
func NewFnSpan ¶
func NewFnSpan(s opentracing.Span) opentracing.Span
NewFnSpan returns a new FnSpan which wraps the specified Span
func NewFnTracer ¶
func NewFnTracer(t opentracing.Tracer) opentracing.Tracer
NewFnTracer returns a new FnTracer which wraps the specified Tracer
func NewPrometheusCollector ¶
func NewPrometheusCollector() (zipkintracer.Collector, error)
NewPrometheusCollector returns a new PrometheusCollector
Types ¶
type ApiAppHandler ¶
type ApiAppHandlerFunc ¶
func (ApiAppHandlerFunc) ServeHTTP ¶
func (f ApiAppHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App)
ServeHTTP calls f(w, r).
type ApiHandler ¶
type ApiHandler interface { // Handle(ctx context.Context) ServeHTTP(w http.ResponseWriter, r *http.Request) }
type ApiHandlerFunc ¶
type ApiHandlerFunc func(w http.ResponseWriter, r *http.Request)
func (ApiHandlerFunc) ServeHTTP ¶
func (f ApiHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP calls f(w, r).
type FnSpan ¶
type FnSpan struct {
opentracing.Span
}
FnSpan is a custom Span that wraps another span which adds some extra behaviour required for sending tracing spans to prometheus
func (FnSpan) FinishWithOptions ¶
func (fns FnSpan) FinishWithOptions(opts opentracing.FinishOptions)
FnSpan implements opentracing.Span
type FnTracer ¶
type FnTracer struct {
opentracing.Tracer
}
FnTracer is a custom Tracer which wraps another another tracer its main purpose is to wrap the underlying Span in a FnSpan, which adds some extra behaviour required for sending tracing spans to prometheus
type Middleware ¶
Middleware just takes a http.Handler and returns one. So the next middle ware must be called within the returned handler or it would be ignored.
type MiddlewareFunc ¶
MiddlewareFunc is a here to allow a plain function to be a middleware.
type PrometheusCollector ¶
type PrometheusCollector struct {
// contains filtered or unexported fields
}
PrometheusCollector is a custom Collector which sends ZipKin traces to Prometheus
func (PrometheusCollector) Close ¶
func (PrometheusCollector) Close() error
PrometheusCollector implements Collector.
func (PrometheusCollector) Collect ¶
func (pc PrometheusCollector) Collect(span *zipkincore.Span) error
PrometheusCollector implements Collector.
type Server ¶
type Server struct { Router *gin.Engine Agent agent.Agent Datastore models.Datastore MQ models.MessageQueue LogDB models.LogStore // contains filtered or unexported fields }
func New ¶
func New(ctx context.Context, ds models.Datastore, mq models.MessageQueue, logDB models.LogStore, opts ...ServerOption) *Server
New creates a new Functions server with the passed in datastore, message queue and API URL
func NewFromEnv ¶
func NewFromEnv(ctx context.Context, opts ...ServerOption) *Server
NewFromEnv creates a new Functions server based on env vars.
func (*Server) AddAppEndpoint ¶
func (s *Server) AddAppEndpoint(method, path string, handler ApiAppHandler)
AddAppEndpoint adds an endpoints to /v1/apps/:app/x
func (*Server) AddAppEndpointFunc ¶
func (s *Server) AddAppEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App))
AddAppEndpoint adds an endpoints to /v1/apps/:app/x
func (*Server) AddAppListener ¶
func (s *Server) AddAppListener(listener extensions.AppListener)
AddAppListener adds a listener that will be notified on App created.
func (*Server) AddCallListener ¶
func (s *Server) AddCallListener(listener extensions.CallListener)
AddCallListener adds a listener that will be fired before and after a function is executed.
func (*Server) AddEndpoint ¶
func (s *Server) AddEndpoint(method, path string, handler ApiHandler)
AddEndpoint adds an endpoint to /v1/x
func (*Server) AddEndpointFunc ¶
func (s *Server) AddEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request))
AddEndpoint adds an endpoint to /v1/x
func (*Server) AddMiddleware ¶
func (s *Server) AddMiddleware(m Middleware)
AddMiddleware add middleware
func (*Server) AddMiddlewareFunc ¶
func (s *Server) AddMiddlewareFunc(m MiddlewareFunc)
AddMiddlewareFunc add middlewarefunc
func (*Server) FireAfterAppCreate ¶
FireAfterAppCreate is used to call all the server's Listeners AfterAppCreate functions.
func (*Server) FireAfterAppDelete ¶
FireAfterAppDelete is used to call all the server's Listeners AfterAppDelete functions.
func (*Server) FireAfterAppUpdate ¶
FireAfterAppUpdate is used to call all the server's Listeners AfterAppUpdate functions.
func (*Server) FireBeforeAppCreate ¶
FireBeforeAppCreate is used to call all the server's Listeners BeforeAppCreate functions.
func (*Server) FireBeforeAppDelete ¶
FireBeforeAppDelete is used to call all the server's Listeners BeforeAppDelete functions.
func (*Server) FireBeforeAppUpdate ¶
FireBeforeAppUpdate is used to call all the server's Listeners BeforeAppUpdate functions.
type ServerOption ¶
type ServerOption func(*Server)
func EnableShutdownEndpoint ¶
func EnableShutdownEndpoint(halt context.CancelFunc) ServerOption
func LimitRequestBody ¶
func LimitRequestBody(max int64) ServerOption
Source Files ¶
- app_listeners.go
- apps_create.go
- apps_delete.go
- apps_get.go
- apps_list.go
- apps_update.go
- call_get.go
- call_list.go
- call_logs.go
- error_response.go
- extension_points.go
- fntracer.go
- init.go
- listeners.go
- middleware.go
- ping.go
- prom_zip_collector.go
- prometheus_metrics.go
- routes_create_update.go
- routes_delete.go
- routes_get.go
- routes_list.go
- runner.go
- server.go
- server_options.go
- shutdown.go
- stats.go
- version.go