Documentation ¶
Overview ¶
Package service acts as a factory for all Pydio services.
Pydio services are wrapped around micro services with additional information and ability to declare themselves to the registry. Services can be of three main different type : - Generic Service : providing a Runner function, they can be used to package any kind of server library as a pydio service - Micro Service : GRPC-based services implementing specific protobuf-services - Web Service : Services adding more logic and exposing Rest APIs defined by the OpenAPI definitions generated from protobufs.
Package provides additional aspects that can be added to any service and declared by "WithXXX" functions.
Index ¶
- Constants
- Variables
- func ApplyMigrations(ctx context.Context, current *version.Version, target *version.Version, ...) (*version.Version, error)
- func FirstRun() *version.Version
- func JWTHttpWrapper(h http.Handler) http.Handler
- func LastKnownVersion(serviceName string) (v *version.Version, e error)
- func Latest() *version.Version
- func NewBackoffClientWrapper() client.Wrapper
- func NewClaimsHandlerWrapper() server.HandlerWrapper
- func NewConfigHandlerWrapper(service micro.Service) server.HandlerWrapper
- func NewConfigHttpHandlerWrapper(h http.Handler, serviceName string) (http.Handler, error)
- func NewDAOClientWrapper(v dao.DAO) client.Wrapper
- func NewDAOHandlerWrapper(val dao.DAO) server.HandlerWrapper
- func NewDAOSubscriberWrapper(val dao.DAO) server.SubscriberWrapper
- func NewLogHandlerWrapper(name string, color uint64) server.HandlerWrapper
- func NewLogHttpHandlerWrapper(h http.Handler, serviceName string, serviceColor uint64) http.Handler
- func PolicyHttpWrapper(h http.Handler) http.Handler
- func RegisterSwaggerJson(json string)
- func RestError401(req *restful.Request, resp *restful.Response, err error)
- func RestError403(req *restful.Request, resp *restful.Response, err error)
- func RestError404(req *restful.Request, resp *restful.Response, err error)
- func RestError423(req *restful.Request, resp *restful.Response, err error)
- func RestError500(req *restful.Request, resp *restful.Response, err error)
- func RestError503(req *restful.Request, resp *restful.Response, err error)
- func RestErrorDetect(req *restful.Request, resp *restful.Response, err error, defaultCode ...int32)
- func Retry(f func() error, seconds ...time.Duration) error
- func SwaggerSpec() *loads.Document
- func UpdateServiceVersion(s Service) error
- func UpdateVersion(serviceName string, v *version.Version) error
- func ValidVersion(v string) *version.Version
- type Checker
- type CheckerFunc
- type ChildrenRunner
- func (c *ChildrenRunner) FilterOutSource(ctx context.Context, sourceName string) bool
- func (c *ChildrenRunner) OnDeleteConfig(callback func(context.Context, string))
- func (c *ChildrenRunner) Start(ctx context.Context, source string) error
- func (c *ChildrenRunner) StartFromInitialConf(ctx context.Context, cfg common.ConfigValues)
- func (c *ChildrenRunner) StopAll(ctx context.Context)
- func (c *ChildrenRunner) Watch(ctx context.Context) error
- type HandlerProvider
- type Migration
- type ProtoEntityReaderWriter
- type RestHandlerBuilder
- type Runner
- type RunnerFunc
- type Service
- type ServiceOption
- func AfterInit(fn func(Service) error) ServiceOption
- func AfterStart(fn func(Service) error) ServiceOption
- func AfterStop(fn func(Service) error) ServiceOption
- func AutoStart(b bool) ServiceOption
- func BeforeInit(fn func(Service) error) ServiceOption
- func BeforeStart(fn func(Service) error) ServiceOption
- func BeforeStop(fn func(Service) error) ServiceOption
- func Cancel(c context.CancelFunc) ServiceOption
- func Context(c context.Context) ServiceOption
- func Dependency(n string, t []string) ServiceOption
- func Description(d string) ServiceOption
- func Fork(b bool) ServiceOption
- func Migrations(migrations []*Migration) ServiceOption
- func Name(n string) ServiceOption
- func PluginBoxes(boxes ...frontend.PluginBox) ServiceOption
- func Port(p string) ServiceOption
- func Regexp(r string) ServiceOption
- func RouterDependencies() ServiceOption
- func Source(s string) ServiceOption
- func Tag(t ...string) ServiceOption
- func Unique(b bool) ServiceOption
- func Version(v string) ServiceOption
- func Watch(fn func(common.ConfigValues)) ServiceOption
- func WithChecker(c Checker) ServiceOption
- func WithGeneric(f func(context.Context, context.CancelFunc) (Runner, Checker, Stopper, error), ...) ServiceOption
- func WithMicro(f func(micro.Service) error) ServiceOption
- func WithMicroChildrenRunner(parentName string, childrenPrefix string, cleanEndpointBeforeDelete bool, ...) ServiceOption
- func WithStorage(d func(dao.DAO) dao.DAO, prefix ...interface{}) ServiceOption
- func WithWeb(handler func() WebHandler, opts ...web.Option) ServiceOption
- func WithWebAuth() ServiceOption
- func WithWebHandler(h func(http.Handler) http.Handler) ServiceOption
- func WithWebSession(excludes ...string) ServiceOption
- type ServiceOptions
- type StatusHandler
- type StopFunctionKey
- type StopHandler
- type Stopper
- type StopperFunc
- type WebHandler
Constants ¶
const ( TYPE_GENERIC = iota TYPE_GRPC TYPE_REST TYPE_API )
Variables ¶
var ( HttpMetaJwtClientApp = "JwtClientApp" HttpMetaJwtIssuer = "JwtIssuer" )
Functions ¶
func ApplyMigrations ¶
func ApplyMigrations(ctx context.Context, current *version.Version, target *version.Version, migrations []*Migration) (*version.Version, error)
ApplyMigrations browse migrations upward on downward and apply them sequentially. It returns a version to be saved as the current valid version of the service, or nil if no changes were necessary. In specific case where current version is 0.0.0 (first run), it only applies first run migration (if any) and returns target version.
func JWTHttpWrapper ¶
JWTHttpWrapper captures and verifies a JWT token if it's present in the headers. Warning: it goes through if there is no JWT => the next handlers must verify if a valid user was found or not.
func LastKnownVersion ¶
LastKnownVersion looks on this server if there was a previous version of this service
func NewBackoffClientWrapper ¶
NewBackoffClientWrapper wraps a client with a backoff option
func NewClaimsHandlerWrapper ¶
func NewClaimsHandlerWrapper() server.HandlerWrapper
NewClaimsHandlerWrapper decodes json claims passed via context metadata ( = headers ) and sets Claims as a proper value in the context
func NewConfigHandlerWrapper ¶
func NewConfigHandlerWrapper(service micro.Service) server.HandlerWrapper
NewConfigHandlerWrapper wraps the service config within the handler so it can be accessed by the handler itself.
func NewConfigHttpHandlerWrapper ¶
NewConfigHttpHandlerWrapper is the same as ConfigHandlerWrapper but for pure http
func NewDAOClientWrapper ¶
NewDAOClientWrapper wraps a db connection so it can be accessed by subsequent client wrappers.
func NewDAOHandlerWrapper ¶
func NewDAOHandlerWrapper(val dao.DAO) server.HandlerWrapper
NewDAOHandlerWrapper wraps a db connection within the handler so it can be accessed by the handler itself.
func NewDAOSubscriberWrapper ¶
func NewDAOSubscriberWrapper(val dao.DAO) server.SubscriberWrapper
NewDAOSubscriberWrapper wraps a db connection for each subscriber
func NewLogHandlerWrapper ¶
func NewLogHandlerWrapper(name string, color uint64) server.HandlerWrapper
NewLogHandlerWrapper wraps a db connection within the handler so it can be accessed by the handler itself.
func NewLogHttpHandlerWrapper ¶
Same but for http
func PolicyHttpWrapper ¶
PolicyHttpWrapper applies relevant policy rules and blocks the request if necessary
func RegisterSwaggerJson ¶
func RegisterSwaggerJson(json string)
func RestError401 ¶
func RestError401(req *restful.Request, resp *restful.Response, err error)
RestError401 logs the error with context and write an Error 401 on the response.
func RestError403 ¶
func RestError403(req *restful.Request, resp *restful.Response, err error)
RestError403 logs the error with context and write an Error 403 on the response.
func RestError404 ¶
func RestError404(req *restful.Request, resp *restful.Response, err error)
RestError404 logs the error with context and writes an Error 404 on the response.
func RestError423 ¶
func RestError423(req *restful.Request, resp *restful.Response, err error)
RestError423 logs the error with context and write an Error 423 on the response.
func RestError500 ¶
func RestError500(req *restful.Request, resp *restful.Response, err error)
RestError500 logs the error with context and write an Error 500 on the response.
func RestError503 ¶
func RestError503(req *restful.Request, resp *restful.Response, err error)
RestError503 logs the error with context and write an Error 503 on the response.
func RestErrorDetect ¶
RestErrorDetect parses the error and tries to detect the correct code.
func SwaggerSpec ¶
func UpdateServiceVersion ¶
UpdateServiceVersion applies migration(s) if necessary and stores new current version for future use.
func UpdateVersion ¶
UpdateVersion writes the version string to file
func ValidVersion ¶
func ValidVersion(v string) *version.Version
ValidVersion creates a version.NewVersion ignoring the error.
Types ¶
type Checker ¶
type Checker interface {
Check() error
}
Checker is a function that checks if the service is correctly Running
type CheckerFunc ¶
type CheckerFunc func() error
func (CheckerFunc) Check ¶
func (f CheckerFunc) Check() error
Check implements the Chercker interface
type ChildrenRunner ¶
type ChildrenRunner struct {
// contains filtered or unexported fields
}
For Regexp based service
func NewChildrenRunner ¶
func NewChildrenRunner(parentService micro.Service, parentName string, childPrefix string) *ChildrenRunner
NewChildrenRunner creates a ChildrenRunner
func (*ChildrenRunner) FilterOutSource ¶
func (c *ChildrenRunner) FilterOutSource(ctx context.Context, sourceName string) bool
FilterOutSource checks in the actual source config if there are some keys that would prevent running on this node
func (*ChildrenRunner) OnDeleteConfig ¶
func (c *ChildrenRunner) OnDeleteConfig(callback func(context.Context, string))
func (*ChildrenRunner) Start ¶
func (c *ChildrenRunner) Start(ctx context.Context, source string) error
Start starts a forked process for a new source
func (*ChildrenRunner) StartFromInitialConf ¶
func (c *ChildrenRunner) StartFromInitialConf(ctx context.Context, cfg common.ConfigValues)
StartFromInitialConf list the sources keys and start them
func (*ChildrenRunner) StopAll ¶
func (c *ChildrenRunner) StopAll(ctx context.Context)
type HandlerProvider ¶
type HandlerProvider func(micro.Service) interface{}
HandlerProvider returns a handler function from a micro service
type Migration ¶
type Migration struct { TargetVersion *version.Version Up func(ctx context.Context) error Down func(ctx context.Context) error }
Migration defines a target version and functions to upgrade and/or downgrade.
type ProtoEntityReaderWriter ¶
type ProtoEntityReaderWriter struct { }
EntityReaderWriter can read and write values using an encoding such as JSON,XML.
func (*ProtoEntityReaderWriter) Read ¶
func (e *ProtoEntityReaderWriter) Read(req *restful.Request, v interface{}) error
Read a serialized version of the value from the request. The Request may have a decompressing reader. Depends on Content-Encoding.
func (*ProtoEntityReaderWriter) Write ¶
func (e *ProtoEntityReaderWriter) Write(resp *restful.Response, status int, v interface{}) error
Write a serialized version of the value on the response. The Response may have a compressing writer. Depends on Accept-Encoding. status should be a valid Http Status code
type RestHandlerBuilder ¶
RestHandlerBuilder builds a RestHandler
type RunnerFunc ¶
type RunnerFunc func() error
func (RunnerFunc) Run ¶
func (f RunnerFunc) Run() error
type Service ¶
type Service interface { registry.Service Init(...ServiceOption) Options() ServiceOptions }
func NewService ¶
func NewService(opts ...ServiceOption) Service
NewService provides everything needed to run a service, no matter the type
type ServiceOption ¶
type ServiceOption func(*ServiceOptions)
func AfterInit ¶
func AfterInit(fn func(Service) error) ServiceOption
func AfterStart ¶
func AfterStart(fn func(Service) error) ServiceOption
func AfterStop ¶
func AfterStop(fn func(Service) error) ServiceOption
func AutoStart ¶
func AutoStart(b bool) ServiceOption
func BeforeStart ¶
func BeforeStart(fn func(Service) error) ServiceOption
func BeforeStop ¶
func BeforeStop(fn func(Service) error) ServiceOption
func Cancel ¶
func Cancel(c context.CancelFunc) ServiceOption
func Context ¶
func Context(c context.Context) ServiceOption
func Dependency ¶
func Dependency(n string, t []string) ServiceOption
func Description ¶
func Description(d string) ServiceOption
func Fork ¶
func Fork(b bool) ServiceOption
func Migrations ¶
func Migrations(migrations []*Migration) ServiceOption
func Name ¶
func Name(n string) ServiceOption
func PluginBoxes ¶
func PluginBoxes(boxes ...frontend.PluginBox) ServiceOption
func Port ¶
func Port(p string) ServiceOption
func Regexp ¶
func Regexp(r string) ServiceOption
func RouterDependencies ¶
func RouterDependencies() ServiceOption
func Source ¶
func Source(s string) ServiceOption
func Tag ¶
func Tag(t ...string) ServiceOption
func Unique ¶
func Unique(b bool) ServiceOption
func Version ¶
func Version(v string) ServiceOption
func Watch ¶
func Watch(fn func(common.ConfigValues)) ServiceOption
func WithChecker ¶
func WithChecker(c Checker) ServiceOption
func WithGeneric ¶
func WithGeneric(f func(context.Context, context.CancelFunc) (Runner, Checker, Stopper, error), opts ...func(Service) (micro.Option, error)) ServiceOption
WithGeneric adds a generic micro service handler to the current service
func WithMicro ¶
func WithMicro(f func(micro.Service) error) ServiceOption
WithMicro adds a micro service handler to the current service
func WithMicroChildrenRunner ¶
func WithStorage ¶
func WithStorage(d func(dao.DAO) dao.DAO, prefix ...interface{}) ServiceOption
WithStorage adds a storage handler to the current service
func WithWeb ¶
func WithWeb(handler func() WebHandler, opts ...web.Option) ServiceOption
WithWeb returns a web handler
func WithWebAuth ¶
func WithWebAuth() ServiceOption
WithWebAuth adds dependencies to the web services and auth wrappers to auth handlers
func WithWebHandler ¶
func WithWebHandler(h func(http.Handler) http.Handler) ServiceOption
func WithWebSession ¶
func WithWebSession(excludes ...string) ServiceOption
type ServiceOptions ¶
type ServiceOptions struct { Name string Tags []string Version string Description string Source string Context context.Context Cancel context.CancelFunc DAO func(dao.DAO) dao.DAO Prefix interface{} Migrations []*Migration Port string Micro micro.Service Web web.Service Dependencies []*dependency // Starting options AutoStart bool Fork bool Unique bool Registry registry.Registry Regexp *regexp.Regexp Flags pflag.FlagSet Checker Checker MinNumberOfNodes int // Before and After funcs BeforeInit []func(Service) error AfterInit []func(Service) error BeforeStart []func(Service) error AfterStart []func(Service) error BeforeStop []func(Service) error AfterStop []func(Service) error OnRegexpMatch func(Service, []string) error // Micro init MicroInit func(Service) error // Web init WebInit func(Service) error // Watcher Watchers []func(common.ConfigValues) // contains filtered or unexported fields }
ServiceOptions stores all options for a pydio service
type StatusHandler ¶
type StatusHandler struct {
// contains filtered or unexported fields
}
StatusHandler provides functionality for getting the status of a service
func (*StatusHandler) SetAddress ¶
func (sh *StatusHandler) SetAddress(a string)
func (*StatusHandler) Status ¶
func (sh *StatusHandler) Status(ctx context.Context, in *empty.Empty, out *proto.StatusResponse) error
Status of the service - If we reach this point, it means that this micro service is correctly up and running
type StopFunctionKey ¶
type StopFunctionKey struct{}
type StopHandler ¶
type StopHandler struct {
// contains filtered or unexported fields
}
StatusHandler provides functionality for stopping a service
func (*StopHandler) SetService ¶
func (s *StopHandler) SetService(srv Service)
type StopperFunc ¶
type StopperFunc func() error
func (StopperFunc) Stop ¶
func (f StopperFunc) Stop() error
type WebHandler ¶
WebHandler defines what functions a web handler must answer to
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package servicecontext performs context values read/write, generally through server or client wrappers
|
Package servicecontext performs context values read/write, generally through server or client wrappers |
Package frontend provides tools to publish static data from within any micro service It implements a simple Union HttpFS to be exposed by a standard net.HttpFileServer interface.
|
Package frontend provides tools to publish static data from within any micro service It implements a simple Union HttpFS to be exposed by a standard net.HttpFileServer interface. |
Package service is a generated protocol buffer package.
|
Package service is a generated protocol buffer package. |
Package resources provides extendable service Handler for managing resource-policy based data.
|
Package resources provides extendable service Handler for managing resource-policy based data. |