server

package
v0.0.0-...-3735483 Latest Latest
Warning

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

Go to latest
Published: May 11, 2018 License: Apache-2.0 Imports: 51 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"
	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

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 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 CallLog

type CallLog struct {
	CallID string `json:"call_id" db:"id"`
	Log    string `json:"log" db:"log"`
}

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

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

func (s *Server) AddRouteListener(listener fnext.RouteListener)

func (*Server) Agent

func (s *Server) Agent() agent.Agent

func (*Server) Datastore

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

implements fnext.ExtServer

func (*Server) Start

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

type ServerNodeType

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

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

Jump to

Keyboard shortcuts

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