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)
- func RegisterExtension(ext fnext.Extension)
- func WriteError(ctx context.Context, w http.ResponseWriter, statuscode int, err error)
- type FnSpan
- type FnTracer
- type PrometheusCollector
- type Server
- func (s *Server) AddAPIMiddleware(m fnext.Middleware)
- func (s *Server) AddAPIMiddlewareFunc(m fnext.MiddlewareFunc)
- func (s *Server) AddAppEndpoint(method, path string, handler fnext.ApiAppHandler)
- func (s *Server) AddAppEndpointFunc(method, path string, ...)
- func (s *Server) AddAppListener(listener fnext.AppListener)
- func (s *Server) AddCallListener(listener fnext.CallListener)
- func (s *Server) AddEndpoint(method, path string, handler fnext.ApiHandler)
- func (s *Server) AddEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request))
- func (s *Server) AddExtension(ext fnext.Extension)
- func (s *Server) AddExtensionByName(name string)
- func (s *Server) AddMiddleware(m fnext.Middleware)
- func (s *Server) AddMiddlewareFunc(m fnext.MiddlewareFunc)
- func (s *Server) AddRootMiddleware(m fnext.Middleware)
- func (s *Server) AddRootMiddlewareFunc(m fnext.MiddlewareFunc)
- func (s *Server) AddRouteEndpoint(method, path string, handler fnext.ApiRouteHandler)
- func (s *Server) AddRouteEndpointFunc(method, path string, ...)
- func (s *Server) Datastore() models.Datastore
- 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) FireAfterAppGet(ctx context.Context, app *models.App) error
- func (s *Server) FireAfterAppUpdate(ctx context.Context, app *models.App) error
- func (s *Server) FireAfterAppsList(ctx context.Context, apps []*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) FireBeforeAppGet(ctx context.Context, appName string) error
- func (s *Server) FireBeforeAppUpdate(ctx context.Context, app *models.App) error
- func (s *Server) FireBeforeAppsList(ctx context.Context, filter *models.AppFilter) error
- func (s *Server) Start(ctx context.Context)
- type ServerNodeType
- type ServerOption
- func EnableShutdownEndpoint(ctx context.Context, halt context.CancelFunc) ServerOption
- func LimitRequestBody(max int64) ServerOption
- func WithAgent(agent agent.Agent) ServerOption
- func WithDBURL(dbURL string) ServerOption
- func WithDatastore(ds models.Datastore) ServerOption
- func WithLogDest(dst, prefix string) ServerOption
- func WithLogLevel(ll string) ServerOption
- func WithLogURL(logstoreURL string) ServerOption
- func WithLogstore(ls models.LogStore) ServerOption
- func WithMQ(mq models.MessageQueue) ServerOption
- func WithMQURL(mqURL string) ServerOption
- func WithRunnerURL(runnerURL string) ServerOption
- func WithTracer(zipkinURL string) ServerOption
- func WithType(t ServerNodeType) ServerOption
Constants ¶
const ( EnvLogLevel = "FN_LOG_LEVEL" EnvLogDest = "FN_LOG_DEST" EnvLogPrefix = "FN_LOG_PREFIX" EnvMQURL = "FN_MQ_URL" EnvDBURL = "FN_DB_URL" EnvLOGDBURL = "FN_LOGSTORE_URL" EnvRunnerURL = "FN_RUNNER_API_URL" EnvNodeType = "FN_NODE_TYPE" EnvPort = "FN_PORT" // be careful, Gin expects this variable to be "port" EnvAPICORS = "FN_API_CORS" EnvZipkinURL = "FN_ZIPKIN_URL" // Defaults DefaultLogLevel = "info" DefaultLogDest = "stderr" DefaultPort = 8080 )
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
func RegisterExtension ¶
RegisterExtension registers the extension so it's available, but does not initialize it. This is generally what third party extensions will use in their init() method.
func WriteError ¶
WriteError easy way to do standard error response, but can set statuscode and error message easier than HandleErrorResponse
Types ¶
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 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 { // TODO this one maybe we have `AddRoute` in extensions? Router *gin.Engine // contains filtered or unexported fields }
func New ¶
func New(ctx context.Context, opts ...ServerOption) *Server
New creates a new Functions server with the opts given. For convenience, users may prefer to use NewFromEnv but New is more flexible if needed.
func NewFromEnv ¶
func NewFromEnv(ctx context.Context, opts ...ServerOption) *Server
NewFromEnv creates a new Functions server based on env vars.
func (*Server) AddAPIMiddleware ¶
func (s *Server) AddAPIMiddleware(m fnext.Middleware)
AddAPIMiddleware add middleware
func (*Server) AddAPIMiddlewareFunc ¶
func (s *Server) AddAPIMiddlewareFunc(m fnext.MiddlewareFunc)
AddAPIMiddlewareFunc add middlewarefunc
func (*Server) AddAppEndpoint ¶
func (s *Server) AddAppEndpoint(method, path string, handler fnext.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 fnext.AppListener)
AddAppListener adds a listener that will be notified on App created.
func (*Server) AddCallListener ¶
func (s *Server) AddCallListener(listener fnext.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 fnext.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) AddExtension ¶
AddExtension both registers an extension and adds it. This is useful during extension development or if you want to build a custom server without using `fn build-server`.
func (*Server) AddExtensionByName ¶
AddExtensionByName This essentially just makes sure the extensions are ordered properly and is what the CLI uses for the `fn build-server` command. Probably not used by much else.
func (*Server) AddMiddleware ¶
func (s *Server) AddMiddleware(m fnext.Middleware)
AddMiddleware DEPRECATED - see AddAPIMiddleware
func (*Server) AddMiddlewareFunc ¶
func (s *Server) AddMiddlewareFunc(m fnext.MiddlewareFunc)
AddMiddlewareFunc DEPRECATED - see AddAPIMiddlewareFunc
func (*Server) AddRootMiddleware ¶
func (s *Server) AddRootMiddleware(m fnext.Middleware)
AddRootMiddleware add middleware add middleware for end user applications
func (*Server) AddRootMiddlewareFunc ¶
func (s *Server) AddRootMiddlewareFunc(m fnext.MiddlewareFunc)
AddRootMiddlewareFunc add middleware for end user applications
func (*Server) AddRouteEndpoint ¶
func (s *Server) AddRouteEndpoint(method, path string, handler fnext.ApiRouteHandler)
AddRouteEndpoint adds an endpoints to /v1/apps/:app/routes/:route/x
func (*Server) AddRouteEndpointFunc ¶
func (s *Server) AddRouteEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route))
AddRouteEndpoint adds an endpoints to /v1/apps/:app/routes/:route/x
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) FireAfterAppGet ¶
FireAfterAppGet runs AppListener's AfterAppGet method.
func (*Server) FireAfterAppUpdate ¶
FireAfterAppUpdate is used to call all the server's Listeners AfterAppUpdate functions.
func (*Server) FireAfterAppsList ¶
FireAfterAppsList runs AppListener's AfterAppsList method.
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) FireBeforeAppGet ¶
FireBeforeAppGet runs AppListener's BeforeAppGet method. todo: All of these listener methods could/should return the 2nd param rather than modifying in place. For instance, if a listener were to change the appName here (maybe prefix it or something for the database), it wouldn't be reflected anywhere else. If this returned appName, then keep passing along the returned appName, it would work.
func (*Server) FireBeforeAppUpdate ¶
FireBeforeAppUpdate is used to call all the server's Listeners BeforeAppUpdate functions.
func (*Server) FireBeforeAppsList ¶
FireBeforeAppsList runs AppListener's BeforeAppsList method.
type ServerNodeType ¶
type ServerNodeType int32
const ( ServerTypeFull ServerNodeType = iota ServerTypeAPI ServerTypeRunner )
func (ServerNodeType) String ¶
func (s ServerNodeType) String() string
type ServerOption ¶
func EnableShutdownEndpoint ¶
func EnableShutdownEndpoint(ctx context.Context, halt context.CancelFunc) ServerOption
func LimitRequestBody ¶
func LimitRequestBody(max int64) ServerOption
func WithAgent ¶
func WithAgent(agent agent.Agent) ServerOption
func WithDBURL ¶
func WithDBURL(dbURL string) ServerOption
func WithDatastore ¶
func WithDatastore(ds models.Datastore) ServerOption
func WithLogDest ¶
func WithLogDest(dst, prefix string) ServerOption
func WithLogLevel ¶
func WithLogLevel(ll string) ServerOption
func WithLogURL ¶
func WithLogURL(logstoreURL string) ServerOption
func WithLogstore ¶
func WithLogstore(ls models.LogStore) ServerOption
func WithMQ ¶
func WithMQ(mq models.MessageQueue) ServerOption
func WithMQURL ¶
func WithMQURL(mqURL string) ServerOption
func WithRunnerURL ¶
func WithRunnerURL(runnerURL string) ServerOption
func WithTracer ¶
func WithTracer(zipkinURL string) ServerOption
TODO need to fix this to handle the nil case better
func WithType ¶
func WithType(t ServerNodeType) 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
- extensions.go
- fntracer.go
- gin_middlewares.go
- hybrid.go
- init.go
- listeners.go
- middleware.go
- ping.go
- profile.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
- version.go