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 ¶
- Variables
- func AddMicroMeta(m micro.Service, k, v string)
- 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 NewConfigHTTPHandlerWrapper(h http.Handler, serviceName string) (http.Handler, error)
- func NewConfigHandlerWrapper(service micro.Service) server.HandlerWrapper
- func NewDAOClientWrapper(v dao.DAO) client.Wrapper
- func NewDAOHandlerWrapper(val dao.DAO) server.HandlerWrapper
- func NewDAOSubscriberWrapper(val dao.DAO) server.SubscriberWrapper
- func NewGenericServer(srv interface{}, opt ...server.Option) server.Server
- func NewLogHTTPHandlerWrapper(h http.Handler, serviceName string, serviceColor uint64) http.Handler
- func NewLogHandlerWrapper(name string, color uint64) server.HandlerWrapper
- 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 Addressable
- 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, retries ...int) error
- func (c *ChildrenRunner) StartFromInitialConf(ctx context.Context, cfg configx.Values)
- func (c *ChildrenRunner) StopAll(ctx context.Context)
- func (c *ChildrenRunner) Watch(ctx context.Context) error
- type Cmd
- type HandlerProvider
- type Migration
- type NonAddressable
- type ProtoEntityReaderWriter
- type RestHandlerBuilder
- type Runnable
- type RunnableFunc
- 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 AutoRestart(b bool) 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 Cluster(c registry.Cluster) 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 Micro(m micro.Service) 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(Service, configx.Values)) ServiceOption
- func WatchPath(path string, fn func(Service, configx.Values)) ServiceOption
- func WithGeneric(f func(...server.Option) server.Server) ServiceOption
- func WithHTTP(handlerFunc func() http.Handler) 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 WithTLSConfig(c *tls.Config) ServiceOption
- func WithWeb(handler func() WebHandler, opts ...micro.Option) ServiceOption
- func WithWebAuth() ServiceOption
- func WithWebHandler(h func(http.Handler) http.Handler) ServiceOption
- func WithWebSession(excludes ...string) ServiceOption
- type ServiceOptions
- type Starter
- type StatusHandler
- type StopFunctionKey
- type StopHandler
- type Stopper
- type StopperFunc
- type WebHandler
Constants ¶
This section is empty.
Variables ¶
var ( // HTTPMetaJwtClientApp constant HTTPMetaJwtClientApp = "JwtClientApp" // HTTPMetaJwtIssuer constant HTTPMetaJwtIssuer = "JwtIssuer" )
Functions ¶
func AddMicroMeta ¶
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 NewConfigHTTPHandlerWrapper ¶
NewConfigHTTPHandlerWrapper is the same as ConfigHandlerWrapper but for pure http
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 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 NewGenericServer ¶
NewGenericServer wraps a micro server out of a simple interface
func NewLogHTTPHandlerWrapper ¶
NewLogHTTPHandlerWrapper wraps a db connection to the HTTP Handler
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 PolicyHTTPWrapper ¶
PolicyHTTPWrapper applies relevant policy rules and blocks the request if necessary
func RegisterSwaggerJSON ¶
func RegisterSwaggerJSON(json string)
RegisterSwaggerJSON receives a json string and adds it to the swagger definition
func RestError401 ¶ added in v1.2.0
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 ¶ added in v1.2.0
RestErrorDetect parses the error and tries to detect the correct code.
func SwaggerSpec ¶ added in v1.2.0
SwaggerSpec returns the swagger specification as a document
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 Addressable ¶
Addressable service definition
type ChildrenRunner ¶
type ChildrenRunner struct {
// contains filtered or unexported fields
}
ChildrenRunner For Regexp based service
func NewChildrenRunner ¶
func NewChildrenRunner(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))
OnDeleteConfig defines what's happening when the config related to the service is deleted
func (*ChildrenRunner) StartFromInitialConf ¶
func (c *ChildrenRunner) StartFromInitialConf(ctx context.Context, cfg configx.Values)
StartFromInitialConf list the sources keys and start them
func (*ChildrenRunner) StopAll ¶
func (c *ChildrenRunner) StopAll(ctx context.Context)
StopAll services
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 NonAddressable ¶
type NonAddressable interface {
NoAddress() string
}
NonAddressable service definition
type ProtoEntityReaderWriter ¶
type ProtoEntityReaderWriter struct { }
ProtoEntityReaderWriter 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 RunnableFunc ¶
type RunnableFunc func() error
RunnableFunc provides ability to use a function as a run service
type Service ¶
type Service interface { registry.Service Init(...ServiceOption) Options() ServiceOptions Done() chan (struct{}) }
Service definition
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)
ServiceOption function to set ServiceOptions
func AfterInit ¶
func AfterInit(fn func(Service) error) ServiceOption
AfterInit option for a service
func AfterStart ¶
func AfterStart(fn func(Service) error) ServiceOption
AfterStart option for a service
func AfterStop ¶
func AfterStop(fn func(Service) error) ServiceOption
AfterStop option for a service
func AutoStart ¶ added in v1.2.2
func AutoStart(b bool) ServiceOption
AutoStart option for a service
func BeforeInit ¶
func BeforeInit(fn func(Service) error) ServiceOption
BeforeInit option for a service
func BeforeStart ¶
func BeforeStart(fn func(Service) error) ServiceOption
BeforeStart option for a service
func BeforeStop ¶
func BeforeStop(fn func(Service) error) ServiceOption
BeforeStop option for a service
func Dependency ¶
func Dependency(n string, t []string) ServiceOption
Dependency option for a service
func Migrations ¶
func Migrations(migrations []*Migration) ServiceOption
Migrations option for a service
func PluginBoxes ¶
func PluginBoxes(boxes ...frontend.PluginBox) ServiceOption
PluginBoxes option for a service
func RouterDependencies ¶ added in v1.0.1
func RouterDependencies() ServiceOption
RouterDependencies option for a service
func WatchPath ¶
func WatchPath(path string, fn func(Service, configx.Values)) ServiceOption
WatchPath option for a service
func WithGeneric ¶
func WithGeneric(f func(...server.Option) server.Server) ServiceOption
WithGeneric runs a micro server
func WithHTTP ¶
func WithHTTP(handlerFunc func() http.Handler) ServiceOption
WithHTTP adds a http 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 WithMicroChildrenRunner(parentName string, childrenPrefix string, cleanEndpointBeforeDelete bool, afterDeleteListener func(context.Context, string)) ServiceOption
WithMicroChildrenRunner option to define a micro server that runs children services
func WithStorage ¶
func WithStorage(d func(dao.DAO) dao.DAO, prefix ...interface{}) ServiceOption
WithStorage adds a storage handler to the current service
func WithTLSConfig ¶
func WithTLSConfig(c *tls.Config) ServiceOption
WithTLSConfig option for a service
func WithWeb ¶
func WithWeb(handler func() WebHandler, opts ...micro.Option) ServiceOption
WithWeb returns a web handler
func WithWebAuth ¶ added in v1.0.1
func WithWebAuth() ServiceOption
WithWebAuth adds auth wrappers to auth handlers
func WithWebHandler ¶ added in v1.4.0
func WithWebHandler(h func(http.Handler) http.Handler) ServiceOption
WithWebHandler option for a service
func WithWebSession ¶ added in v1.2.0
func WithWebSession(excludes ...string) ServiceOption
WithWebSession option for a service
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 TLSConfig *tls.Config Micro Runnable Web web.Service Dependencies []*dependency // Starting options AutoStart bool AutoRestart bool Fork bool Unique bool Cluster registry.Cluster Registry registry.Registry Regexp *regexp.Regexp Flags pflag.FlagSet 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 MicroCancel context.CancelFunc // Web init WebInit func(Service) error // Watcher Watchers map[string][]func(Service, configx.Values) // contains filtered or unexported fields }
ServiceOptions stores all options for a pydio service
type StatusHandler ¶ added in v1.2.2
type StatusHandler struct {
// contains filtered or unexported fields
}
StatusHandler provides functionality for getting the status of a service
func (*StatusHandler) SetAddress ¶ added in v1.6.2
func (sh *StatusHandler) SetAddress(a string)
SetAddress for a service
func (*StatusHandler) Status ¶ added in v1.2.2
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 StopHandler ¶ added in v1.2.2
type StopHandler struct {
// contains filtered or unexported fields
}
StopHandler provides functionality for stopping a service
func (*StopHandler) ProcessEvent ¶
ProcessEvent handler
func (*StopHandler) SetService ¶ added in v1.6.2
func (s *StopHandler) SetService(srv Service)
SetService handler
type StopperFunc ¶
type StopperFunc func() error
StopperFunc allows to use a function as a stopper service
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. |