Documentation
¶
Index ¶
- Variables
- func ErrorIsNotFound(err error) bool
- func NewGrpcHealthServer(service *Service) grpc_health_v1.HealthServer
- func SubmitJob[T any](ctx context.Context, s *Service, job workerpool.Job[T]) error
- func ToContext(ctx context.Context, service *Service) context.Context
- type Checker
- type CheckerFunc
- type Option
- func WithBackgroundConsumer(deque func(_ context.Context) error) Option
- func WithCache(name string, rawCache cache.RawCache) Option
- func WithCacheManager() Option
- func WithConfig(cfg any) Option
- func WithDatastore(opts ...pool.Option) Option
- func WithDatastoreConnection(postgresqlConnection string, readOnly bool) Option
- func WithDatastoreConnectionWithName(name string, postgresqlConnection string, readOnly bool, opts ...pool.Option) Option
- func WithDatastoreConnectionWithOptions(name string, opts ...pool.Option) Option
- func WithDatastoreManager() Option
- func WithDriver(driver ServerDriver) Option
- func WithEnableGRPCServerReflection() Option
- func WithEnvironment(environment string) Option
- func WithGRPCPort(port string) Option
- func WithGRPCServer(grpcServer *grpc.Server) Option
- func WithGRPCServerListener(listener net.Listener) Option
- func WithHTTPClient(opts ...client.HTTPOption) Option
- func WithHTTPHandler(h http.Handler) Option
- func WithHealthCheckPath(path string) Option
- func WithInMemoryCache(name string) Option
- func WithLogger(opts ...util.Option) Option
- func WithName(name string) Option
- func WithRegisterEvents(evt ...events.EventI) Option
- func WithRegisterPublisher(reference string, queueURL string) Option
- func WithRegisterServerOauth2Client() Option
- func WithRegisterSubscriber(reference string, queueURL string, handlers ...queue.SubscribeWorker) Option
- func WithTelemetry(opts ...telemetry.Option) Option
- func WithTranslation(translationsFolder string, languages ...string) Option
- func WithVersion(version string) Option
- func WithWorkerPoolOptions(options ...workerpool.Option) Option
- type ServerDriver
- type Service
- func (s *Service) AddCleanupMethod(f func(ctx context.Context))
- func (s *Service) AddHealthCheck(checker Checker)
- func (s *Service) AddPreStartMethod(f func(ctx context.Context, s *Service))
- func (s *Service) AddPublisherStartup(f func(ctx context.Context, s *Service))
- func (s *Service) AddStartupError(err error)
- func (s *Service) AddSubscriberStartup(f func(ctx context.Context, s *Service))
- func (s *Service) CacheManager() cache.Manager
- func (s *Service) Config() any
- func (s *Service) DatastoreManager() datastore.Manager
- func (s *Service) Environment() string
- func (s *Service) EventsManager() events.Manager
- func (s *Service) GetRawCache(name string) (cache.RawCache, bool)
- func (s *Service) GetStartupErrors() []error
- func (s *Service) H() http.Handler
- func (s *Service) HTTPClientManager() client.Manager
- func (s *Service) HandleHealth(w http.ResponseWriter, _ *http.Request)
- func (s *Service) HandleHealthByDefault(w http.ResponseWriter, r *http.Request)
- func (s *Service) HealthCheckers() []Checker
- func (s *Service) Init(ctx context.Context, opts ...Option)
- func (s *Service) LocalizationManager() localization.Manager
- func (s *Service) Log(ctx context.Context) *util.LogEntry
- func (s *Service) Name() string
- func (s *Service) QueueManager() queue.Manager
- func (s *Service) Run(ctx context.Context, address string) error
- func (s *Service) SLog(ctx context.Context) *slog.Logger
- func (s *Service) SecurityManager() security.Manager
- func (s *Service) Stop(ctx context.Context)
- func (s *Service) TLSEnabled() bool
- func (s *Service) TelemetryManager() telemetry.Manager
- func (s *Service) Version() string
- func (s *Service) WorkManager() workerpool.Manager
Constants ¶
This section is empty.
Variables ¶
var ErrHealthCheckFailed = errors.New("health check failed")
var ErrTLSPathsNotProvided = errors.New("TLS certificate path or key path not provided")
Functions ¶
func ErrorIsNotFound ¶ added in v1.67.11
ErrorIsNotFound checks if an error represents a "not found" condition. It handles multiple error types: - Database errors: gorm.ErrRecordNotFound, sql.ErrNoRows (via ErrorIsNoRows) - gRPC errors: codes.NotFound - Generic errors: error messages containing "not found" (case-insensitive).
func NewGrpcHealthServer ¶ added in v1.13.3
func NewGrpcHealthServer(service *Service) grpc_health_v1.HealthServer
Types ¶
type Checker ¶ added in v1.7.13
type Checker interface {
CheckHealth() error
}
Checker wraps the CheckHealth method.
CheckHealth returns nil if the resource is healthy, or a non-nil error if the resource is not healthy. CheckHealth must be safe to call from multiple goroutines.
type CheckerFunc ¶ added in v1.7.13
type CheckerFunc func() error
CheckerFunc is an adapter type to allow the use of ordinary functions as health checks. If f is a function with the appropriate signature, CheckerFunc(f) is a Checker that calls f.
func (CheckerFunc) CheckHealth ¶ added in v1.7.13
func (f CheckerFunc) CheckHealth() error
CheckHealth calls f().
type Option ¶
func WithBackgroundConsumer ¶ added in v1.43.0
WithBackgroundConsumer sets a background consumer function for the worker pool.
func WithCacheManager ¶ added in v1.62.0
func WithCacheManager() Option
WithCacheManager adds a cache manager to the service.
func WithConfig ¶ added in v1.42.0
WithConfig Option that helps to specify or override the configuration object of our service.
func WithDatastore ¶ added in v1.42.0
func WithDatastoreConnection ¶ added in v1.42.0
WithDatastoreConnection Option method to store a connection that will be utilized when connecting to the database.
func WithDatastoreConnectionWithName ¶ added in v1.42.0
func WithDatastoreConnectionWithOptions ¶ added in v1.63.0
func WithDatastoreManager ¶ added in v1.63.0
func WithDatastoreManager() Option
WithDatastoreManager creates and initializes a datastore manager with the given options. This is the low-level function that should rarely be called directly - use WithDatastore instead.
func WithDriver ¶ added in v1.56.1
func WithDriver(driver ServerDriver) Option
WithDriver setsup a driver, mostly useful when writing tests against the frame service.
func WithEnableGRPCServerReflection ¶ added in v1.43.0
func WithEnableGRPCServerReflection() Option
WithEnableGRPCServerReflection enables gRPC server reflection.
func WithEnvironment ¶ added in v1.55.0
WithEnvironment specifies the environment the service will utilize.
func WithGRPCPort ¶ added in v1.43.0
WithGRPCPort specifies the gRPC port for the server to bind to.
func WithGRPCServer ¶ added in v1.43.0
WithGRPCServer specifies an instantiated gRPC server with an implementation that can be utilized to handle incoming requests.
func WithGRPCServerListener ¶ added in v1.43.0
WithGRPCServerListener specifies a user-preferred gRPC listener instead of the default provided one.
func WithHTTPClient ¶ added in v1.59.1
func WithHTTPClient(opts ...client.HTTPOption) Option
WithHTTPClient configures the HTTP client used by the service. This allows customizing the HTTP client's behavior such as timeout, transport, etc.
func WithHTTPHandler ¶ added in v1.43.0
WithHTTPHandler specifies an HTTP handlers that can be used to handle inbound HTTP requests.
func WithHealthCheckPath ¶ added in v1.42.0
WithHealthCheckPath Option checks that the system is up and running.
func WithInMemoryCache ¶ added in v1.62.0
WithInMemoryCache adds an in-memory cache with the given name.
func WithLogger ¶ added in v1.38.0
WithLogger Option that helps with initialization of our internal dbLogger.
func WithRegisterEvents ¶ added in v1.42.0
WithRegisterEvents registers events for the service. All events are unique and shouldn't share a name otherwise the last one registered will take precedence.
func WithRegisterPublisher ¶ added in v1.42.0
WithRegisterPublisher Option to register publishing path referenced within the system.
func WithRegisterServerOauth2Client ¶ added in v1.62.1
func WithRegisterServerOauth2Client() Option
func WithRegisterSubscriber ¶ added in v1.42.0
func WithRegisterSubscriber(reference string, queueURL string, handlers ...queue.SubscribeWorker) Option
WithRegisterSubscriber Option to register a new subscription handlers.
func WithTelemetry ¶ added in v1.63.0
WithTelemetry adds required telemetry config options to the service.
func WithTranslation ¶ added in v1.62.0
WithTranslation Option that helps to specify or override the configuration object of our service.
func WithVersion ¶ added in v1.55.0
WithVersion specifies the version the service will utilize.
func WithWorkerPoolOptions ¶ added in v1.43.0
func WithWorkerPoolOptions(options ...workerpool.Option) Option
WithWorkerPoolOptions provides a way to set custom options for the ants worker pool. Renamed from WithAntsOptions and changed parameter type.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service framework struct to hold together all application components An instance of this type scoped to stay for the lifetime of the application. It is pushed and pulled from contexts to make it easy to pass around.
func FromContext ¶
FromContext obtains a service instance being propagated through the context.
func NewService ¶
NewService creates a new instance of Service with the name and supplied options. Internally it calls NewServiceWithContext and creates a background context for use.
func NewServiceWithContext ¶ added in v1.25.3
NewServiceWithContext creates a new instance of Service with context, name and supplied options It is used together with the Init option to setup components of a service that is not yet running.
func (*Service) AddCleanupMethod ¶
AddCleanupMethod Adds user defined functions to be run just before completely stopping the service. These are responsible for properly and gracefully stopping active components.
func (*Service) AddHealthCheck ¶
AddHealthCheck Adds health checks that are run periodically to ascertain the system is ok The arguments are implementations of the checker interface and should work with just about any system that is given to them.
func (*Service) AddPreStartMethod ¶ added in v1.1.3
AddPreStartMethod Adds user defined functions that can be run just before the service starts receiving requests but is fully initialized.
func (*Service) AddPublisherStartup ¶ added in v1.62.0
AddPublisherStartup Adds publisher initialization functions that run before subscribers.
func (*Service) AddStartupError ¶ added in v1.62.0
AddStartupError stores errors that occur during startup initialization.
func (*Service) AddSubscriberStartup ¶ added in v1.62.0
AddSubscriberStartup Adds subscriber initialization functions that run after publishers.
func (*Service) CacheManager ¶ added in v1.62.0
CacheManager returns the service's cache manager.
func (*Service) DatastoreManager ¶ added in v1.63.0
DatastoreManager returns the service's datastore manager.
func (*Service) Environment ¶ added in v1.7.13
Environment gets the runtime environment of the service.
func (*Service) EventsManager ¶ added in v1.64.8
func (*Service) GetRawCache ¶ added in v1.62.0
GetRawCache is a convenience method to get a raw cache by name from the service.
func (*Service) GetStartupErrors ¶ added in v1.62.0
GetStartupErrors returns all errors that occurred during startup.
func (*Service) HTTPClientManager ¶ added in v1.63.0
HTTPClientManager obtains an instrumented http client for making appropriate calls downstream.
func (*Service) HandleHealth ¶ added in v1.12.5
func (s *Service) HandleHealth(w http.ResponseWriter, _ *http.Request)
HandleHealth returns 200 if it is healthy, 500 otherwise.
func (*Service) HandleHealthByDefault ¶ added in v1.12.6
func (s *Service) HandleHealthByDefault(w http.ResponseWriter, r *http.Request)
HandleHealthByDefault returns 200 if it is healthy, 500 when there is an err or 404 otherwise.
func (*Service) HealthCheckers ¶ added in v1.7.13
func (*Service) Init ¶ added in v1.0.4
Init evaluates the options provided as arguments and supplies them to the service object. If called after initial startup, it will execute any new startup methods immediately.
func (*Service) LocalizationManager ¶ added in v1.63.0
func (s *Service) LocalizationManager() localization.Manager
func (*Service) Name ¶ added in v1.4.0
Name gets the name of the service. Its the first argument used when NewService is called.
func (*Service) QueueManager ¶ added in v1.63.0
func (*Service) SecurityManager ¶ added in v1.63.0
func (*Service) Stop ¶
Stop Used to gracefully run clean up methods ensuring all requests that were being handled are completed well without interuptions.
func (*Service) TLSEnabled ¶ added in v1.13.0
func (*Service) TelemetryManager ¶ added in v1.66.0
func (*Service) WorkManager ¶ added in v1.62.0
func (s *Service) WorkManager() workerpool.Manager