serviceregistry

package
v0.4.24 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: BSD-3-Clause-Clear Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBRegister added in v0.3.0

type DBRegister struct {
	// Required is a flag that indicates whether the service requires a database connection.
	Required bool
	// Migrations is an embedded filesystem that contains the Goose SQL migrations for the service.
	// This is required to support the `migrate` command or the `runMigrations` configuration option.
	// More information on Goose can be found at https://github.com/pressly/goose
	Migrations *embed.FS
}

DBRegister is a struct that holds the information needed to register a service with a database

type HandlerServer

type HandlerServer func(ctx context.Context, mux *runtime.ServeMux, server any) error

type Namespace added in v0.4.18

type Namespace struct {
	Mode     string
	Services []Service
}

namespace represents a namespace in the service registry.

type RegisterFunc

type RegisterFunc func(RegistrationParams) (Impl any, HandlerServer HandlerServer)

type Registration

type Registration struct {
	// Namespace is the namespace of the service. One or more gRPC services can be registered under
	// the same namespace.
	Namespace string
	// ServiceDesc is the gRPC service descriptor. For non-gRPC services, this can be mocked out,
	// but at minimum, the ServiceName field must be set
	ServiceDesc *grpc.ServiceDesc
	// RegisterFunc is the function that will be called to register the service
	RegisterFunc RegisterFunc

	// DB is optional and used to register the service with a database
	DB DBRegister
}

Registration is a struct that holds the information needed to register a service

type RegistrationParams

type RegistrationParams struct {
	// Config scoped to the service config. Since the main config contains all the service configs,
	// which could have need-to-know information we don't want to expose it to all services.
	Config ServiceConfig
	// OTDF is the OpenTDF server that can be used to interact with the OpenTDFServer instance.
	OTDF *server.OpenTDFServer
	// DBClient is the database client that can be used to interact with the database. This client
	// is scoped to the service namespace and will not be shared with other service namespaces.
	DBClient *db.Client
	// SDK is the OpenTDF SDK that can be used to interact with the OpenTDF SDK. This is useful for
	// gRPC Inter Process Communication (IPC) between services. This ensures the services are
	// communicating with each other by contract as well as supporting the various deployment models
	// that OpenTDF supports.
	SDK *sdk.SDK
	// Logger is the logger that can be used to log messages. This logger is scoped to the service
	Logger *logger.Logger

	// RegisterWellKnownConfig is a function that can be used to register a well-known configuration
	WellKnownConfig func(namespace string, config any) error
	// RegisterReadinessCheck is a function that can be used to register a readiness check for the
	// service. This is useful for services that need to perform some initialization before they are
	// ready to serve requests. This function should be called in the RegisterFunc function.
	RegisterReadinessCheck func(namespace string, check func(context.Context) error) error
}

RegistrationParams is a struct that holds the parameters needed to register a service with the service registry. These parameters are passed to the RegisterFunc function defined in the Registration struct.

type Registry added in v0.4.18

type Registry map[string]Namespace

Registry represents a map of service namespaces.

func NewServiceRegistry added in v0.4.18

func NewServiceRegistry() Registry

NewServiceRegistry creates a new instance of the service registry.

func (Registry) GetNamespace added in v0.4.18

func (reg Registry) GetNamespace(namespace string) (Namespace, error)

GetNamespace returns the namespace with the given name from the service registry.

func (Registry) RegisterCoreService added in v0.4.18

func (reg Registry) RegisterCoreService(r Registration) error

RegisterCoreService registers a core service with the given registration information. It calls the RegisterService method of the Registry instance with the provided registration and service type "core". Returns an error if the registration fails.

func (Registry) RegisterService added in v0.4.18

func (reg Registry) RegisterService(r Registration, mode string) error

RegisterService registers a service in the service registry. It takes a Registration object and a mode string as parameters. The Registration object contains information about the service to be registered, such as the namespace and service description. The mode string specifies the mode in which the service should be registered. It returns an error if the service is already registered in the specified namespace.

func (Registry) Shutdown added in v0.4.18

func (reg Registry) Shutdown()

Shutdown stops all the services in the service registry. It iterates over each namespace and service in the registry, checks if the service has a Close method and if it has been started, and then calls the Close method to stop the service.

type Service

type Service struct {
	Registration

	// Started is a flag that indicates whether the service has been started
	Started bool
	// Close is a function that can be called to close the service
	Close func()
	// contains filtered or unexported fields
}

Service is a struct that holds the registration information for a service as well as the state of the service within the instance of the platform.

func (*Service) RegisterGRPCServer added in v0.4.18

func (s *Service) RegisterGRPCServer(server *grpc.Server) error

RegisterGRPCServer registers the gRPC server with the service implementation. It checks if the service implementation is registered and then registers the service with the server. It returns an error if the service implementation is not registered.

func (*Service) RegisterHTTPServer deprecated added in v0.4.18

func (s *Service) RegisterHTTPServer(ctx context.Context, mux *runtime.ServeMux) error

Deprecated: RegisterHTTPServer is deprecated and should not be used going forward. We will be looking onto other alternatives like bufconnect to replace this. RegisterHTTPServer registers an HTTP server with the service. It takes a context, a ServeMux, and an implementation function as parameters. If the service did not register a handler, it returns an error.

func (*Service) Start added in v0.4.18

func (s *Service) Start(ctx context.Context, params RegistrationParams) error

Start starts the service and performs necessary initialization steps. It returns an error if the service is already started or if there is an issue running database migrations.

type ServiceConfig

type ServiceConfig map[string]any

Jump to

Keyboard shortcuts

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