service

package
v5.0.0-...-b98a0e9 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: AGPL-3.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIRoute = "api"
)

Variables

View Source
var (
	ContextKey = serviceKey{}
)

Functions

func FirstRun

func FirstRun() *version.Version

FirstRun returns version "zero".

func Latest

func Latest() *version.Version

Latest retrieves current common Cells version.

func RegisterPluginBoxes

func RegisterPluginBoxes(boxes ...PluginBox)

RegisterPluginBoxes adds a PluginBox to registry

func RegisterSwaggerJSON

func RegisterSwaggerJSON(json string)

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

func SwaggerSpec

func SwaggerSpec() *loads.Document

SwaggerSpec returns the swagger specification as a document

func UpdateServiceVersion

func UpdateServiceVersion(ctx context.Context, 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 Convertible

type Convertible interface {
	As(interface{}) bool
}

type IDable

type IDable interface {
	ID() string
}

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 MigratorFunc

type MigratorFunc func(topCtx, fromCtx, toCtx context.Context, dryRun bool, status chan MigratorStatus) (map[string]int, error)

type MigratorStatus

type MigratorStatus struct {
	Status string
	Total  int64
	Count  int64
}

type PluginBox

type PluginBox struct {
	Box        fs.FS
	Exposes    []string
	ExposeFunc func() []string
}

PluginBox exposes web assets

func GetRegisteredPluginBoxes

func GetRegisteredPluginBoxes() []PluginBox

GetRegisteredPluginBoxes lists all registered PluginBox

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

func ForceRegister(b bool) ServiceOption

ForceRegister option for a service

func Fork

func Fork(f bool) ServiceOption

Fork option for a service

func ID

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

WithHTTP adds a http micro service handler to the current service

func WithHTTPOptions

WithHTTPOptions adds a http microservice handler to the current service, passing ServiceOptions to initializer

func WithMigrateIterator

func WithMigrateIterator(ctxKey any, lister func(ctx context.Context) []string) ServiceOption

WithMigrateIterator injects an additional level of iteration for update service version

func WithNamedStorageDrivers

func WithNamedStorageDrivers(name string, f ...any) ServiceOption

WithNamedStorageDrivers allows supporting multiple set of drivers

func WithPureHTTP

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

func WithServerScheme(scheme string) ServiceOption

func WithStorageDrivers

func WithStorageDrivers(f ...any) ServiceOption

WithStorageDrivers adds a storage handler to the current service

func WithStorageMigrator

func WithStorageMigrator(d MigratorFunc) ServiceOption

WithStorageMigrator provides a Migrate function from one DAO to another

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 WithWebMiddleware

func WithWebMiddleware(middleware func(h http.Handler) http.Handler) ServiceOption

WithWebMiddleware appends additional middleware

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:"-"`
	MigrateIterator struct {
		ContextKey any
		Lister     func(ctx context.Context) []string
	} `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:"-"`
	BeforeRequest []func(context.Context) (context.Context, error) `json:"-"`
	AfterServe    []func(context.Context) error                    `json:"-"`

	WebMiddlewares []func(h http.Handler) http.Handler

	StorageOptions StorageOptions `json:"-"`
	// contains filtered or unexported fields
}

ServiceOptions stores all options for a pydio service

func (*ServiceOptions) GetRegistry

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

GetRegistry returns the context registry

func (*ServiceOptions) Logger

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

Logger returns a local logger

func (*ServiceOptions) RootContext

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

RootContext returns root context

func (*ServiceOptions) SetRegistry

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

SetRegistry sets the registry in the root context

type Stopper

type Stopper func() error

type StorageDrivers

type StorageDrivers []any

func (*StorageDrivers) Register

func (s *StorageDrivers) Register(f any)

type StorageOption

type StorageOption func(options *StorageOptions)

func WithStoragePrefix

func WithStoragePrefix(i interface{}) StorageOption

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

type StorageOptions

type StorageOptions struct {
	SupportedDrivers map[string][]any
	Handler          any
	Migrator         MigratorFunc
	// contains filtered or unexported fields
}

func (*StorageOptions) Prefix

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

func (*StorageOptions) ToMeta

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