server

package
v0.0.0-...-c0df949 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2018 License: Apache-2.0 Imports: 42 Imported by: 0

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

View Source
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

View Source
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

func RegisterExtension(ext fnext.Extension)

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

func WriteError(ctx context.Context, w http.ResponseWriter, statuscode int, err error)

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) Finish

func (fns FnSpan) Finish()

FnSpan implements opentracing.Span

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

func (FnTracer) StartSpan

func (fnt FnTracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span

FnTracer implements opentracing.Tracer Override StartSpan to wrap the returned Span in a FnSpan

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

func (s *Server) AddExtension(ext fnext.Extension)

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

func (s *Server) AddExtensionByName(name string)

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) Datastore

func (s *Server) Datastore() models.Datastore

implements fnext.ExtServer

func (*Server) FireAfterAppCreate

func (s *Server) FireAfterAppCreate(ctx context.Context, app *models.App) error

FireAfterAppCreate is used to call all the server's Listeners AfterAppCreate functions.

func (*Server) FireAfterAppDelete

func (s *Server) FireAfterAppDelete(ctx context.Context, app *models.App) error

FireAfterAppDelete is used to call all the server's Listeners AfterAppDelete functions.

func (*Server) FireAfterAppGet

func (s *Server) FireAfterAppGet(ctx context.Context, app *models.App) error

FireAfterAppGet runs AppListener's AfterAppGet method.

func (*Server) FireAfterAppUpdate

func (s *Server) FireAfterAppUpdate(ctx context.Context, app *models.App) error

FireAfterAppUpdate is used to call all the server's Listeners AfterAppUpdate functions.

func (*Server) FireAfterAppsList

func (s *Server) FireAfterAppsList(ctx context.Context, apps []*models.App) error

FireAfterAppsList runs AppListener's AfterAppsList method.

func (*Server) FireBeforeAppCreate

func (s *Server) FireBeforeAppCreate(ctx context.Context, app *models.App) error

FireBeforeAppCreate is used to call all the server's Listeners BeforeAppCreate functions.

func (*Server) FireBeforeAppDelete

func (s *Server) FireBeforeAppDelete(ctx context.Context, app *models.App) error

FireBeforeAppDelete is used to call all the server's Listeners BeforeAppDelete functions.

func (*Server) FireBeforeAppGet

func (s *Server) FireBeforeAppGet(ctx context.Context, appName string) error

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

func (s *Server) FireBeforeAppUpdate(ctx context.Context, app *models.App) error

FireBeforeAppUpdate is used to call all the server's Listeners BeforeAppUpdate functions.

func (*Server) FireBeforeAppsList

func (s *Server) FireBeforeAppsList(ctx context.Context, filter *models.AppFilter) error

FireBeforeAppsList runs AppListener's BeforeAppsList method.

func (*Server) Start

func (s *Server) Start(ctx context.Context)

type ServerNodeType

type ServerNodeType int32
const (
	ServerTypeFull ServerNodeType = iota
	ServerTypeAPI
	ServerTypeRunner
)

func (ServerNodeType) String

func (s ServerNodeType) String() string

type ServerOption

type ServerOption func(context.Context, *Server) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL