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 RegisterExtension(ext fnext.Extension)
- func WriteError(ctx context.Context, w http.ResponseWriter, statuscode int, err error)
- type CallLog
- 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) AddRouteListener(listener fnext.RouteListener)
- func (s *Server) Agent() agent.Agent
- func (s *Server) Datastore() models.Datastore
- 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 WithAgentFromEnv() ServerOption
- func WithDBURL(dbURL string) ServerOption
- func WithDatastore(ds models.Datastore) ServerOption
- func WithExtraCtx(extraCtx context.Context) ServerOption
- func WithFullAgent() ServerOption
- func WithGRPCPort(port int) ServerOption
- func WithJaeger(jaegerURL string) ServerOption
- func WithLogDest(dst, prefix string) ServerOption
- func WithLogLevel(ll string) ServerOption
- func WithLogURL(logstoreURL string) ServerOption
- func WithLogstore(ls models.LogStore) ServerOption
- func WithLogstoreFromDatastore() ServerOption
- func WithMQ(mq models.MessageQueue) ServerOption
- func WithMQURL(mqURL string) ServerOption
- func WithNodeCert(cert string) ServerOption
- func WithNodeCertAuthority(ca string) ServerOption
- func WithNodeCertKey(key string) ServerOption
- func WithPrometheus() ServerOption
- func WithRunnerURL(runnerURL string) ServerOption
- func WithType(t ServerNodeType) ServerOption
- func WithWebPort(port int) ServerOption
- func WithZipkin(zipkinURL string) 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" EnvRunnerAddresses = "FN_RUNNER_ADDRESSES" EnvNodeType = "FN_NODE_TYPE" EnvPort = "FN_PORT" // be careful, Gin expects this variable to be "port" EnvGRPCPort = "FN_GRPC_PORT" EnvAPICORS = "FN_API_CORS" EnvZipkinURL = "FN_ZIPKIN_URL" EnvJaegerURL = "FN_JAEGER_URL" // Certificates to communicate with other FN nodes EnvCert = "FN_NODE_CERT" EnvCertKey = "FN_NODE_CERT_KEY" EnvCertAuth = "FN_NODE_CERT_AUTHORITY" EnvProcessCollectorList = "FN_PROCESS_COLLECTOR_LIST" EnvLBPlacementAlg = "FN_PLACER" // Defaults DefaultLogLevel = "info" DefaultLogDest = "stderr" DefaultPort = 8080 DefaultGRPCPort = 9190 )
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 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 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 an AppListener for the server to use.
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) AddRouteListener ¶
func (s *Server) AddRouteListener(listener fnext.RouteListener)
type ServerNodeType ¶
type ServerNodeType int32
const ( ServerTypeFull ServerNodeType = iota ServerTypeAPI ServerTypeLB ServerTypeRunner ServerTypePureRunner )
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 WithAgentFromEnv ¶
func WithAgentFromEnv() ServerOption
WithAgentFromEnv must be provided as the last server option because it relies on all other options being set first.
func WithDBURL ¶
func WithDBURL(dbURL string) ServerOption
func WithDatastore ¶
func WithDatastore(ds models.Datastore) ServerOption
func WithExtraCtx ¶
func WithExtraCtx(extraCtx context.Context) ServerOption
WithExtraCtx appends a context to the list of contexts the server will watch for cancellations / errors / signals.
func WithFullAgent ¶
func WithFullAgent() ServerOption
WithFullAgent is a shorthand for WithAgent(... create a full agent here ...)
func WithGRPCPort ¶
func WithGRPCPort(port int) ServerOption
func WithJaeger ¶
func WithJaeger(jaegerURL string) 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 WithLogstoreFromDatastore ¶
func WithLogstoreFromDatastore() ServerOption
func WithMQ ¶
func WithMQ(mq models.MessageQueue) ServerOption
func WithMQURL ¶
func WithMQURL(mqURL string) ServerOption
func WithNodeCert ¶
func WithNodeCert(cert string) ServerOption
func WithNodeCertAuthority ¶
func WithNodeCertAuthority(ca string) ServerOption
func WithNodeCertKey ¶
func WithNodeCertKey(key string) ServerOption
func WithPrometheus ¶
func WithPrometheus() ServerOption
func WithRunnerURL ¶
func WithRunnerURL(runnerURL string) ServerOption
func WithType ¶
func WithType(t ServerNodeType) ServerOption
func WithWebPort ¶
func WithWebPort(port int) ServerOption
func WithZipkin ¶
func WithZipkin(zipkinURL string) 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
- gin_middlewares.go
- hybrid.go
- init.go
- listeners.go
- middleware.go
- ping.go
- profile.go
- route_listeners.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