Documentation
¶
Index ¶
- type AppContext
- type AppContextOption
- func WithAWSManager(manager *aws.AWSManager) AppContextOption
- func WithBlameManager(bw *blame.BlameManager) AppContextOption
- func WithCacheManager(config *cache.CacheConfig) AppContextOption
- func WithCloudManager(manager cloud.CloudManager) AppContextOption
- func WithCryptoManager(manager *cryptography.CryptoManager) AppContextOption
- func WithDatabase(database database.Database) AppContextOption
- func WithDebugEnabled() AppContextOption
- func WithEmailClient(client email.EmailClient) AppContextOption
- func WithHttpClientManager(url string, opts ...http.RequestOption) AppContextOption
- func WithInitBlameManager(opts *blame.BlameManagerOption) AppContextOption
- func WithLogger(logger *log.Log) AppContextOption
- func WithMongoManager(manager *mongo.MongoManager) AppContextOption
- func WithNATSManager(url string, options ...nats.Option) AppContextOption
- func WithOciManager(manager *oci.OCIManager) AppContextOption
- func WithPasetoManager(opts ...paseto.PasetoOption) AppContextOption
- func WithRedisManager(manager *redis.RedisManager) AppContextOption
- func WithServiceID(serviceId string) AppContextOption
- func WithSessionManager(manager *session.SessionManager) AppContextOption
- func WithStoreManager(manager *store.StoreManager) AppContextOption
- func WithVault(vlt *vault.Vault) AppContextOption
- type DefaultContext
- type DependencyDetails
- type DependencyStatus
- type ServiceContext
- func (s *ServiceContext) Background() context.Context
- func (ctx *ServiceContext) CheckDependencies() (string, DependencyDetails)
- func (ctx *ServiceContext) FetchGinRequestSlogFields() []types.Field
- func (s *ServiceContext) GetAppContextCorrelationID() (types.CorrelationID, bool)
- func (s *ServiceContext) GetAppContextRequestID() (types.RequestID, bool)
- func (ctx *ServiceContext) GetCookieSessionID() string
- func (ctx *ServiceContext) GetCorrelationID() types.CorrelationID
- func (ctx *ServiceContext) GetGinContextCorrelationID() types.CorrelationID
- func (ctx *ServiceContext) GetGinContextRequestID() types.RequestID
- func (ctx *ServiceContext) GetGinCtxRecordsName() (*string, error)
- func (ctx *ServiceContext) GetGinCtxServiceName() (*types.Service, error)
- func (s *ServiceContext) GetLogger() (*log.Log, bool)
- func (s *ServiceContext) GetMetadata() (map[string]string, bool)
- func (ctx *ServiceContext) GetNATSManager() *nats.NATSManager
- func (s *ServiceContext) GetPreField() *ServiceContext
- func (ctx *ServiceContext) GetRequestID() types.RequestID
- func (s *ServiceContext) GetServiceID() string
- func (s *ServiceContext) GetTraceID() (string, bool)
- func (s *ServiceContext) RecoverFromException()
- func (s *ServiceContext) RunSafely(fn func())
- func (ctx *ServiceContext) SlogDebug(message string, withFields ...types.Field)
- func (ctx *ServiceContext) SlogError(message string, withFields ...types.Field)
- func (ctx *ServiceContext) SlogEvent(msg *nats.Msg, withFields ...types.Field) []types.Field
- func (ctx *ServiceContext) SlogEventDebug(logMessage string, natsMsg *nats.Msg, withFields ...types.Field)
- func (ctx *ServiceContext) SlogEventError(logMessage string, natsMsg *nats.Msg, withFields ...types.Field)
- func (ctx *ServiceContext) SlogEventInfo(logMessage string, natsMsg *nats.Msg, withFields ...types.Field)
- func (ctx *ServiceContext) SlogEventWarn(logMessage string, natsMsg *nats.Msg, withFields ...types.Field)
- func (ctx *ServiceContext) SlogFatal(message string, withFields ...types.Field)
- func (ctx *ServiceContext) SlogFields(withFields ...types.Field) []types.Field
- func (ctx *ServiceContext) SlogInfo(message string, withFields ...types.Field)
- func (ctx *ServiceContext) SlogWarn(message string, withFields ...types.Field)
- func (s *ServiceContext) WithCancel() (*ServiceContext, context.CancelFunc)
- func (s *ServiceContext) WithDeadline(deadline time.Time) (*ServiceContext, context.CancelFunc)
- func (s *ServiceContext) WithGeneratedCorrelationID() *ServiceContext
- func (s *ServiceContext) WithGeneratedRequestID() *ServiceContext
- func (s *ServiceContext) WithLogger(logger *log.Log) *ServiceContext
- func (s *ServiceContext) WithMetadata(metadata map[string]string) *ServiceContext
- func (s *ServiceContext) WithRequestID(requestID string) *ServiceContext
- func (s *ServiceContext) WithTimeout(timeout time.Duration) (*ServiceContext, context.CancelFunc)
- func (s *ServiceContext) WithTraceID(traceID string) *ServiceContext
- func (s *ServiceContext) WithValue(key, val any) *ServiceContext
- type ServiceContextOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppContext ¶
type AppContext struct {
*blame.BlameManager
*paseto.PasetoManager
*log.Log
*nats.NATSManager
*service.Services
*http.HttpClientManager
*vault.Vault
*redis.RedisManager
*aws.AWSManager
database.Database
cache.Cache[string, any]
*cryptography.CryptoManager
email.EmailClient
*oci.OCIManager
*mongo.MongoManager
*session.SessionManager
*store.StoreManager
cloud.CloudManager
// contains filtered or unexported fields
}
AppContext holds application-specific context data.
func NewAppContext ¶
func NewAppContext(opts ...AppContextOption) *AppContext
NewAppContext creates a new AppContext with the given options.
func (*AppContext) AttachServices ¶
func (appCtx *AppContext) AttachServices(services *service.Services)
AttachServices sets the services for the AppContext.
func (*AppContext) GetBlameManager ¶
func (ctx *AppContext) GetBlameManager() *blame.BlameManager
GetBlameManager retrieves the BlameManager from the App context.
type AppContextOption ¶
type AppContextOption func(*AppContext)
AppContextOption is a function that modifies the AppContext.
func WithAWSManager ¶
func WithAWSManager(manager *aws.AWSManager) AppContextOption
WithAWSManager sets the aws manager for the AppContext.
func WithBlameManager ¶
func WithBlameManager(bw *blame.BlameManager) AppContextOption
WithBlameManager sets the blame manager for the AppContext.
func WithCacheManager ¶
func WithCacheManager(config *cache.CacheConfig) AppContextOption
WithCacheManager sets the cache manager for the AppContext.
func WithCloudManager ¶
func WithCloudManager(manager cloud.CloudManager) AppContextOption
WithCloudManager sets the cloud manager for the AppContext
func WithCryptoManager ¶
func WithCryptoManager(manager *cryptography.CryptoManager) AppContextOption
WithCryptoManager sets the crypto manager for the AppContext.
func WithDatabase ¶
func WithDatabase(database database.Database) AppContextOption
WithDatabase sets the database for the AppContext.
func WithDebugEnabled ¶
func WithDebugEnabled() AppContextOption
WithDebugEnabled sets the DebugEnabled to true for the AppContext.
func WithEmailClient ¶
func WithEmailClient(client email.EmailClient) AppContextOption
WithEmailClient sets the email client for the AppContext.
func WithHttpClientManager ¶
func WithHttpClientManager(url string, opts ...http.RequestOption) AppContextOption
WithHttpClientManager sets the http client manager for the AppContext.
func WithInitBlameManager ¶
func WithInitBlameManager(opts *blame.BlameManagerOption) AppContextOption
WithInitBlameManager sets the blame manager for the AppContext.
func WithLogger ¶
func WithLogger(logger *log.Log) AppContextOption
WithLogger sets the logger wrapper for the AppContext.
func WithMongoManager ¶
func WithMongoManager(manager *mongo.MongoManager) AppContextOption
WithMongoManager sets the mongo manager for the AppContext.
func WithNATSManager ¶
func WithNATSManager(url string, options ...nats.Option) AppContextOption
WithNATSManager sets the nats manager for the AppContext.
func WithOciManager ¶
func WithOciManager(manager *oci.OCIManager) AppContextOption
WithOciManager sets the oci manager for the AppContext.
func WithPasetoManager ¶
func WithPasetoManager(opts ...paseto.PasetoOption) AppContextOption
WithPasetoManager sets the paseto manager for the AppContext.
func WithRedisManager ¶
func WithRedisManager(manager *redis.RedisManager) AppContextOption
WithRedisManager sets the redis manager for the AppContext.
func WithServiceID ¶
func WithServiceID(serviceId string) AppContextOption
WithServiceId sets the service ID for the AppContext.
func WithSessionManager ¶
func WithSessionManager(manager *session.SessionManager) AppContextOption
WithSessionManager sets the session manager for the AppContext.
func WithStoreManager ¶
func WithStoreManager(manager *store.StoreManager) AppContextOption
WithStoreManager sets the store manager for the AppContext.
func WithVault ¶
func WithVault(vlt *vault.Vault) AppContextOption
WithVault sets the vault for the AppContext.
type DefaultContext ¶
DefaultContext is a default implementation of the Context interface.
func DefaultContextWithTimeout ¶
func DefaultContextWithTimeout(timeout time.Duration) (DefaultContext, context.CancelFunc)
DefaultContextWithTimeout creates a new default context with a timeout.
func NewDefaultContext ¶
func NewDefaultContext() *DefaultContext
NewDefaultContext creates a new DefaultContext.
type DependencyDetails ¶
type DependencyDetails struct {
Logger DependencyStatus `json:"logger,omitzero"`
Database DependencyStatus `json:"database,omitzero"`
Nats DependencyStatus `json:"nats,omitzero"`
Blame DependencyStatus `json:"blame,omitzero"`
Paseto DependencyStatus `json:"paseto,omitzero"`
}
DependencyDetails struct to represent the health of multiple dependencies
func NewDependencyDetails ¶
func NewDependencyDetails() DependencyDetails
type DependencyStatus ¶
type DependencyStatus struct {
Status string `json:"status"` // "ok", "error", "degraded", "fail"
Message string `json:"message"` // Descriptive message
}
DependencyStatus struct to represent the health of a single dependency
func NewDependencyStatus ¶
func NewDependencyStatus( status, message string) DependencyStatus
NewDependencyStatus creates a new instance of DependencyStatus
type ServiceContext ¶
type ServiceContext struct {
*DefaultContext
*AppContext
*gin.Context
}
ServiceContext embeds AppContext and Gin Context and default Context of Go
func NewServiceContext ¶
func NewServiceContext(opts ...ServiceContextOption) *ServiceContext
NewServiceContext initializes a ServiceContext with the provided options.
func (*ServiceContext) Background ¶
func (s *ServiceContext) Background() context.Context
Background creates a new context with a new background context.
func (*ServiceContext) CheckDependencies ¶
func (ctx *ServiceContext) CheckDependencies() (string, DependencyDetails)
CheckDependencies checks the health of the dependencies and returns the overall status
func (*ServiceContext) FetchGinRequestSlogFields ¶
func (ctx *ServiceContext) FetchGinRequestSlogFields() []types.Field
FetchGinRequestSlogFields fetched a requestId and correlationid as slice of fields
func (*ServiceContext) GetAppContextCorrelationID ¶
func (s *ServiceContext) GetAppContextCorrelationID() (types.CorrelationID, bool)
GetAppContextCorrelationID retrieves the correlation ID from the AppContext.
func (*ServiceContext) GetAppContextRequestID ¶
func (s *ServiceContext) GetAppContextRequestID() (types.RequestID, bool)
GetAppContextRequestID retrieves the request ID from the AppContext.
func (*ServiceContext) GetCookieSessionID ¶
func (ctx *ServiceContext) GetCookieSessionID() string
GetCookieSessionID returns the session ID from the cookie.
func (*ServiceContext) GetCorrelationID ¶
func (ctx *ServiceContext) GetCorrelationID() types.CorrelationID
GetCorrelationID returns the correlation ID from the AppContext or the Gin context.
func (*ServiceContext) GetGinContextCorrelationID ¶
func (ctx *ServiceContext) GetGinContextCorrelationID() types.CorrelationID
GetGinContextCorrelationID returns the correlation ID from the Gin context.
func (*ServiceContext) GetGinContextRequestID ¶
func (ctx *ServiceContext) GetGinContextRequestID() types.RequestID
GetGinContextRequestID returns the request ID from the Gin context.
func (*ServiceContext) GetGinCtxRecordsName ¶
func (ctx *ServiceContext) GetGinCtxRecordsName() (*string, error)
func (*ServiceContext) GetGinCtxServiceName ¶
func (ctx *ServiceContext) GetGinCtxServiceName() (*types.Service, error)
GetGinCtxServiceName retrieves the service name from the gin.Context.
func (*ServiceContext) GetLogger ¶
func (s *ServiceContext) GetLogger() (*log.Log, bool)
GetLogger retrieves the logger from the AppContext.
func (*ServiceContext) GetMetadata ¶
func (s *ServiceContext) GetMetadata() (map[string]string, bool)
GetMetadata retrieves metadata from the AppContext.
func (*ServiceContext) GetNATSManager ¶
func (ctx *ServiceContext) GetNATSManager() *nats.NATSManager
GetNATSManager retrieves the NATSManager from the App context.
func (*ServiceContext) GetPreField ¶
func (s *ServiceContext) GetPreField() *ServiceContext
func (*ServiceContext) GetRequestID ¶
func (ctx *ServiceContext) GetRequestID() types.RequestID
GetRequestID returns the request ID from the AppContext or the Gin context.
func (*ServiceContext) GetServiceID ¶
func (s *ServiceContext) GetServiceID() string
GetServiceID retrieves the service ID from the AppContext.
func (*ServiceContext) GetTraceID ¶
func (s *ServiceContext) GetTraceID() (string, bool)
GetTraceID retrieves the trace ID from the AppContext.
func (*ServiceContext) RecoverFromException ¶
func (s *ServiceContext) RecoverFromException()
RecoverFromException recovers from panics and logs the stack trace
func (*ServiceContext) RunSafely ¶
func (s *ServiceContext) RunSafely(fn func())
func (*ServiceContext) SlogDebug ¶
func (ctx *ServiceContext) SlogDebug(message string, withFields ...types.Field)
func (*ServiceContext) SlogError ¶
func (ctx *ServiceContext) SlogError(message string, withFields ...types.Field)
func (*ServiceContext) SlogEvent ¶
SlogEvent returns a slice of types.Field with message and correlation fields and additional fields.
func (*ServiceContext) SlogEventDebug ¶
func (ctx *ServiceContext) SlogEventDebug(logMessage string, natsMsg *nats.Msg, withFields ...types.Field)
SlogEventDebug logs a message at the DebugLevel with NATS event metadata.
func (*ServiceContext) SlogEventError ¶
func (ctx *ServiceContext) SlogEventError(logMessage string, natsMsg *nats.Msg, withFields ...types.Field)
SlogEventError logs a message at the ErrorLevel with NATS event metadata.
func (*ServiceContext) SlogEventInfo ¶
func (ctx *ServiceContext) SlogEventInfo(logMessage string, natsMsg *nats.Msg, withFields ...types.Field)
SlogEventInfo logs a message at the InfoLevel with NATS event metadata.
func (*ServiceContext) SlogEventWarn ¶
func (ctx *ServiceContext) SlogEventWarn(logMessage string, natsMsg *nats.Msg, withFields ...types.Field)
SlogEventWarn logs a message at the WarnLevel with NATS event metadata.
func (*ServiceContext) SlogFatal ¶
func (ctx *ServiceContext) SlogFatal(message string, withFields ...types.Field)
func (*ServiceContext) SlogFields ¶
func (ctx *ServiceContext) SlogFields(withFields ...types.Field) []types.Field
SlogFields returns a slice of types.Field with request and correlation fields and additional fields.
func (*ServiceContext) SlogInfo ¶
func (ctx *ServiceContext) SlogInfo(message string, withFields ...types.Field)
SlogInfo logs a message at the InfoLevel.
func (*ServiceContext) SlogWarn ¶
func (ctx *ServiceContext) SlogWarn(message string, withFields ...types.Field)
func (*ServiceContext) WithCancel ¶
func (s *ServiceContext) WithCancel() (*ServiceContext, context.CancelFunc)
WithCancel creates a new ServiceContext with a cancel function.
func (*ServiceContext) WithDeadline ¶
func (s *ServiceContext) WithDeadline(deadline time.Time) (*ServiceContext, context.CancelFunc)
WithDeadline creates a new ServiceContext with a deadline.
func (*ServiceContext) WithGeneratedCorrelationID ¶
func (s *ServiceContext) WithGeneratedCorrelationID() *ServiceContext
WithGeneratedCorrelationID adds a generated correlation ID to the AppContext.
func (*ServiceContext) WithGeneratedRequestID ¶
func (s *ServiceContext) WithGeneratedRequestID() *ServiceContext
WithGeneratedRequestID adds a generated request ID to the AppContext.
func (*ServiceContext) WithLogger ¶
func (s *ServiceContext) WithLogger(logger *log.Log) *ServiceContext
WithLogger adds a logger to the AppContext.
func (*ServiceContext) WithMetadata ¶
func (s *ServiceContext) WithMetadata(metadata map[string]string) *ServiceContext
WithMetadata adds metadata (as a map) to the AppContext.
func (*ServiceContext) WithRequestID ¶
func (s *ServiceContext) WithRequestID(requestID string) *ServiceContext
WithRequestID adds a request ID to the AppContext.
func (*ServiceContext) WithTimeout ¶
func (s *ServiceContext) WithTimeout(timeout time.Duration) (*ServiceContext, context.CancelFunc)
WithTimeout creates a new ServiceContext with a timeout.
func (*ServiceContext) WithTraceID ¶
func (s *ServiceContext) WithTraceID(traceID string) *ServiceContext
WithTraceID adds a trace ID to the AppContext for distributed tracing.
func (*ServiceContext) WithValue ¶
func (s *ServiceContext) WithValue(key, val any) *ServiceContext
WithValue adds a key-value pair to the AppContext.
type ServiceContextOption ¶
type ServiceContextOption func(*ServiceContext)
ServiceContextOption is a function that can be used to configure a ServiceContext.
func WithAppContext ¶
func WithAppContext(appCtx *AppContext) ServiceContextOption
WithAppContext sets the AppContext for the ServiceContext.
func WithGinContext ¶
func WithGinContext(ginCtx *gin.Context) ServiceContextOption
WithGinContext sets the Gin Context for the ServiceContext.