service

package
v4.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: AGPL-3.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstRun

func FirstRun() *version.Version

FirstRun returns version "zero".

func Latest

func Latest() *version.Version

Latest retrieves current common Cells version.

func RegisterSwaggerJSON

func RegisterSwaggerJSON(json string)

RegisterSwaggerJSON receives a json string and adds it to the swagger definition

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

func RestErrorDetect(req *restful.Request, resp *restful.Response, err error, defaultCode ...int32)

RestErrorDetect parses the error and tries to detect the correct code.

func SwaggerSpec

func SwaggerSpec() *loads.Document

SwaggerSpec returns the swagger specification as a document

func UpdateServiceVersion

func UpdateServiceVersion(opts *ServiceOptions) error

UpdateServiceVersion applies migration(s) if necessary and stores new current version for future use.

func ValidVersion

func ValidVersion(v string) *version.Version

ValidVersion creates a version.NewVersion ignoring the error.

Types

type ChildrenRunner

type ChildrenRunner struct {
	// contains filtered or unexported fields
}

ChildrenRunner For Regexp based service

func NewChildrenRunner

func NewChildrenRunner(parentName string, childPrefix string, secondaryPrefix ...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) Start

func (c *ChildrenRunner) Start(ctx context.Context, source string, retries ...int) error

Start starts a forked process for a new source

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

func (*ChildrenRunner) Watch

func (c *ChildrenRunner) Watch(ctx context.Context) error

Watch watches the configuration changes for new sources

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

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 Service

type Service interface {
	Init(opts ...ServiceOption)
	Options() *ServiceOptions
	Metadata() map[string]string
	ID() string
	Name() string
	Version() string
	Tags() []string
	Start(oo ...registry.RegisterOption) error
	Stop(oo ...registry.RegisterOption) error
	OnServe(oo ...registry.RegisterOption) error
	ServerScheme() string
	Server() server.Server
	Is(status registry.Status) bool
	As(i interface{}) bool
}

func NewService

func NewService(opts ...ServiceOption) Service

NewService creates a service and directly register it as StatusStopped

type ServiceOption

type ServiceOption func(*ServiceOptions)

ServiceOption provides a functional option

func AfterServe

func AfterServe(f func(ctx context.Context) error) ServiceOption

AfterServe registers a callback that is run after Server is finally started (non-blocking)

func AutoRestart

func AutoRestart(b bool) ServiceOption

AutoRestart option for a service

func AutoStart

func AutoStart(b bool) ServiceOption

AutoStart option for a service

func Context

func Context(c context.Context) ServiceOption

Context option for a service

func Description

func Description(d string) ServiceOption

Description option for a service

func ForceRegister added in v4.0.1

func ForceRegister(b bool) ServiceOption

ForceRegister option for a service

func Fork

func Fork(f bool) ServiceOption

Fork option for a service

func ID added in v4.2.2

func ID(n string) ServiceOption

ID option for a service

func Metadata

func Metadata(name, value string) ServiceOption

Metadata registers a key/value metadata

func Migrations

func Migrations(migrations []*Migration) ServiceOption

Migrations option for a service

func Name

func Name(n string) ServiceOption

Name option for a service

func PluginBoxes

func PluginBoxes(boxes ...frontend.PluginBox) ServiceOption

PluginBoxes option for a service

func Source

func Source(s string) ServiceOption

Source option for a service

func Tag

func Tag(t ...string) ServiceOption

Tag option for a service

func Unique

func Unique(b bool) ServiceOption

Unique option for a service

func WithChildrenRunner

func WithChildrenRunner(parentName string, childrenPrefix string, cleanEndpointBeforeDelete bool, afterDeleteListener func(context.Context, string), secondaryPrefix ...string) []ServiceOption

WithChildrenRunner option to define a micro server that runs children services

func WithGRPC

WithGRPC adds a GRPC service handler to the current service

func WithGRPCStop

func WithGRPCStop(f func(context.Context, grpc.ServiceRegistrar) error) ServiceOption

WithGRPCStop hooks to the grpc server stop

func WithGeneric

func WithGeneric(f func(context.Context, *generic.Server) error) ServiceOption

WithGeneric adds a http micro service handler to the current service

func WithGenericStop

func WithGenericStop(f func(context.Context, *generic.Server) error) ServiceOption

WithGenericStop adds a http micro service handler to the current service

func WithHTTP

func WithHTTP(f func(context.Context, server.HttpMux) error) ServiceOption

WithHTTP adds a http micro service handler to the current service

func WithHTTPStop

func WithHTTPStop(f func(context.Context, server.HttpMux) error) ServiceOption

func WithIndexer

func WithIndexer(fd dao.DaoWrapperFunc, opts ...StorageOption) ServiceOption

WithIndexer adds an indexer handler to the current service

func WithPureHTTP added in v4.0.1

func WithPureHTTP(f func(context.Context, server.HttpMux) error) ServiceOption

WithPureHTTP adds a http micro service handler to the current service

func WithServer

func WithServer(s server.Server) ServiceOption

WithServer directly presets the server.Server instance

func WithServerScheme added in v4.0.1

func WithServerScheme(scheme string) ServiceOption

func WithStorage

func WithStorage(fd dao.DaoWrapperFunc, opts ...StorageOption) 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(ctx context.Context) WebHandler) ServiceOption

WithWeb returns a web handler

func WithWebSession

func WithWebSession(excludes ...string) ServiceOption

func WithWebStop

func WithWebStop(handler func(ctx context.Context) error) ServiceOption

WithWebStop registers an optional callback to perform clean operations on stop WithWeb already registers a serverStop callback to remove rest patterns

type ServiceOptions

type ServiceOptions struct {
	Name string   `json:"name"`
	ID   string   `json:"id"`
	Tags []string `json:"tags"`

	Version     string `json:"version"`
	Description string `json:"description"`
	Source      string `json:"source"`

	Metadata map[string]string `json:"metadata"`

	Migrations []*Migration `json:"-"`

	// Port      string
	TLSConfig *tls.Config

	Server server.Server `json:"-"`

	// Starting options
	ForceRegister bool `json:"-"`
	AutoStart     bool `json:"-"`
	AutoRestart   bool `json:"-"`
	Fork          bool `json:"-"`
	Unique        bool `json:"-"`

	// Before and After funcs
	BeforeStart []func(context.Context) (context.Context, error) `json:"-"`
	BeforeStop  []func(context.Context) error                    `json:"-"`
	AfterServe  []func(context.Context) error                    `json:"-"`

	UseWebSession      bool     `json:"-"`
	WebSessionExcludes []string `json:"-"`

	Storages []*StorageOptions `json:"-"`
	// contains filtered or unexported fields
}

ServiceOptions stores all options for a pydio service

func (*ServiceOptions) GetRegistry added in v4.2.3

func (o *ServiceOptions) GetRegistry() registry.Registry

GetRegistry returns the context registry

func (*ServiceOptions) Logger added in v4.2.3

func (o *ServiceOptions) Logger() log.ZapLogger

Logger returns a local logger

func (*ServiceOptions) RootContext added in v4.2.3

func (o *ServiceOptions) RootContext() context.Context

RootContext returns root context

func (*ServiceOptions) SetRegistry added in v4.2.3

func (o *ServiceOptions) SetRegistry(r registry.Registry)

SetRegistry sets the registry in the root context

type Stopper

type Stopper func() error

type StorageOption

type StorageOption func(options *StorageOptions)

func WithStorageDefaultDriver

func WithStorageDefaultDriver(d func() (string, string)) StorageOption

WithStorageDefaultDriver provides a default driver/dsn couple if not set in the configuration

func WithStorageMigrator

func WithStorageMigrator(d dao.MigratorFunc) StorageOption

WithStorageMigrator provides a Migrate function from one DAO to another

func WithStoragePrefix

func WithStoragePrefix(i interface{}) StorageOption

WithStoragePrefix sets a prefix to be used differently depending on driver name

func WithStorageSupport

func WithStorageSupport(dd ...string) StorageOption

WithStorageSupport declares wich drivers can be supported by this service

type StorageOptions

type StorageOptions struct {
	StorageKey       string
	SupportedDrivers []string
	DefaultDriver    dao.DriverProviderFunc
	Migrator         dao.MigratorFunc
	// contains filtered or unexported fields
}

func (*StorageOptions) Prefix

func (o *StorageOptions) Prefix(options *ServiceOptions) string

func (*StorageOptions) ToMeta added in v4.0.1

func (o *StorageOptions) ToMeta() string

type WebHandler

type WebHandler interface {
	SwaggerTags() []string
	Filter() func(string) string
}

WebHandler defines what functions a web handler must answer to

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
Package frontend provides tools to publish static data from within any micro service
sessions/securecookie
Package securecookie provides tools for using Bolt as a standard persistence layer for services
Package securecookie provides tools for using Bolt as a standard persistence layer for services
Package resources provides extendable service Handler for managing resource-policy based data.
Package resources provides extendable service Handler for managing resource-policy based data.

Jump to

Keyboard shortcuts

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