server

package
v0.0.0-...-2853c3c Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: Apache-2.0 Imports: 32 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  = "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

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.

Types

type ApiAppHandler

type ApiAppHandler interface {
	// Handle(ctx context.Context)
	ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App)
}

type ApiAppHandlerFunc

type ApiAppHandlerFunc func(w http.ResponseWriter, r *http.Request, app *models.App)

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 AppListener

type AppListener interface {
	// BeforeAppCreate called right before creating App in the database
	BeforeAppCreate(ctx context.Context, app *models.App) error
	// AfterAppCreate called after creating App in the database
	AfterAppCreate(ctx context.Context, app *models.App) error
	// BeforeAppUpdate called right before updating App in the database
	BeforeAppUpdate(ctx context.Context, app *models.App) error
	// AfterAppUpdate called after updating App in the database
	AfterAppUpdate(ctx context.Context, app *models.App) error
	// BeforeAppDelete called right before deleting App in the database
	BeforeAppDelete(ctx context.Context, app *models.App) error
	// AfterAppDelete called after deleting App in the database
	AfterAppDelete(ctx context.Context, app *models.App) error
}

AppListener is an interface used to inject custom code at key points in app lifecycle.

type Middleware

type Middleware interface {
	Chain(next http.Handler) http.Handler
}

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

type MiddlewareFunc func(next http.Handler) http.Handler

MiddlewareFunc is a here to allow a plain function to be a middleware.

func (MiddlewareFunc) Chain

func (m MiddlewareFunc) Chain(next http.Handler) http.Handler

Chain used to allow middlewarefuncs to be middleware.

type RunnerListener

type RunnerListener interface {
	// BeforeDispatch called before a function run
	BeforeDispatch(ctx context.Context, route *models.Route) error
	// AfterDispatch called after a function run
	AfterDispatch(ctx context.Context, route *models.Route) error
}

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

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

AddAppListener adds a listener that will be notified on App created.

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

func (s *Server) AddRunnerListener(listener RunnerListener)

AddRunListeners adds a listener that will be fired before and after a function run.

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

func (s *Server) FireAfterDispatch(ctx context.Context, route *models.Route) error

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

func (s *Server) FireBeforeDispatch(ctx context.Context, route *models.Route) error

func (*Server) Start

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

type ServerOption

type ServerOption func(*Server)

func EnableShutdownEndpoint

func EnableShutdownEndpoint(halt context.CancelFunc) ServerOption

func LimitRequestBody

func LimitRequestBody(max int64) ServerOption

Jump to

Keyboard shortcuts

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