Documentation
      ¶
    
    
  
    
  
    Index ¶
- func StreamContextTaggerInterceptor(tagger ContextTagger) func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
 - func StreamLoggingInterceptor(requestBody bool, logger Logger) grpc.StreamServerInterceptor
 - func StreamMetricsInterceptor(metrics Metrics) grpc.StreamServerInterceptor
 - func UnaryContextTaggerInterceptor(tagger ContextTagger) ...
 - func UnaryLoggingInterceptor(requestBody bool, logger Logger) grpc.UnaryServerInterceptor
 - func UnaryMetricsInterceptor(metrics Metrics) grpc.UnaryServerInterceptor
 - func WithTags(ctx context.Context, tags Tags) context.Context
 - type All
 - type Cache
 - type CacheProvider
 - type ContextTagger
 - type ContextTaggerFunc
 - type ContextTaggerProvider
 - type Database
 - type DatabaseProvider
 - type Logger
 - type LoggingProvider
 - type MessageHandler
 - type Metrics
 - type MetricsProvider
 - type Stream
 - type StreamProvider
 - type Tags
 
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StreamContextTaggerInterceptor ¶
func StreamContextTaggerInterceptor(tagger ContextTagger) func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
StreamContextTaggerInterceptor is a grpc stream interceptor that tags the inbound context
func StreamLoggingInterceptor ¶
func StreamLoggingInterceptor(requestBody bool, logger Logger) grpc.StreamServerInterceptor
StreamLoggingInterceptor adds a stream logging interceptor to the server
func StreamMetricsInterceptor ¶
func StreamMetricsInterceptor(metrics Metrics) grpc.StreamServerInterceptor
StreamMetricsInterceptor returns a grpc stream server interceptor that records metrics
func UnaryContextTaggerInterceptor ¶
func UnaryContextTaggerInterceptor(tagger ContextTagger) func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
UnaryContextTaggerInterceptor is a grpc unary interceptor that tags the inbound context
func UnaryLoggingInterceptor ¶
func UnaryLoggingInterceptor(requestBody bool, logger Logger) grpc.UnaryServerInterceptor
UnaryLoggingInterceptor adds a unary logging interceptor to the server
func UnaryMetricsInterceptor ¶
func UnaryMetricsInterceptor(metrics Metrics) grpc.UnaryServerInterceptor
UnaryMetricsInterceptor returns a grpc unary server interceptor that collects metrics
Types ¶
type Cache ¶
type Cache interface {
	// Get returns a value from the cache by key
	Get(ctx context.Context, key string) (string, error)
	// Set sets a value in the cache by key
	Set(ctx context.Context, key string, value string, ttl time.Duration) error
	// Delete deletes a value from the cache by key
	Delete(ctx context.Context, key string) error
	// Lock locks a key in the cache for a given ttl. It returns true if the lock was acquired, false otherwise.
	Lock(ctx context.Context, key string, ttl time.Duration) (bool, error)
	// Unlock unlocks a key in the cache
	Unlock(ctx context.Context, key string, ttl time.Duration) error
	// Once runs a function once for a given key. It returns true if the function was run, false otherwise.
	Once(ctx context.Context, key string, ttl time.Duration, fn func(ctx context.Context) error) (bool, error)
}
    Cache is an interface for caching data
type CacheProvider ¶
CacheProvider is a function that returns a Cache
type ContextTagger ¶
type ContextTagger interface {
	// TagContext tags the context with the given contextID and grpcMethod
	TagContext(ctx context.Context) Tags
}
    ContextTagger is an interface for tagging contexts
type ContextTaggerFunc ¶
ContextTaggerFunc is a function that implements the ContextTagger interface
func (ContextTaggerFunc) TagContext ¶
func (c ContextTaggerFunc) TagContext(ctx context.Context) Tags
TagContext tags the context with the given contextID and grpcMethod
type ContextTaggerProvider ¶
ContextTaggerProvider is a function that returns a ContextTagger
type Database ¶
type Database interface {
	// Migrate runs the database migrations
	Migrate(ctx context.Context) error
	// Close closes the database connection
	Close() error
}
    Database is an interface that represents a database client. It is used to run migrations and close the connection. Type casting is required to use the client.
type DatabaseProvider ¶
DatabaseProvider is a function that returns a Database
type Logger ¶
type Logger interface {
	// Info logs an info message
	Info(ctx context.Context, msg string, tags ...map[string]any)
	// Error logs an error message
	Error(ctx context.Context, msg string, tags ...map[string]any)
	// Warn logs a warning message
	Warn(ctx context.Context, msg string, tags ...map[string]any)
	// Debug logs a debug message
	Debug(ctx context.Context, msg string, tags ...map[string]any)
}
    Logger is an interface for logging
type LoggingProvider ¶
LoggingProvider is a function that returns a Logger
type MessageHandler ¶
MessageHandler is a function that handles a message from a stream
type Metrics ¶
type Metrics interface {
	// Inc increments the value in a gauge
	Inc(name string, labels ...string)
	// Dec decrements the value in a gauge
	Dec(name string, labels ...string)
	// Observe records the value in a histogram
	Observe(name string, value float64, labels ...string)
	// Set sets the value in a gauge
	Set(name string, value float64, labels ...string)
	// RegisterHistogram registers a new histogram with the given name and labels
	RegisterHistogram(name string, labels ...string)
	// RegisterGauge registers a new gauge with the given name and labels
	RegisterGauge(name string, labels ...string)
}
    Metrics is an interface for collecting metrics
type MetricsProvider ¶
MetricsProvider is a function that returns a Metrics
type Stream ¶
type Stream interface {
	// Publish publishes a message to the stream
	Publish(ctx context.Context, topic string, message map[string]any) error
	// Subscribe subscribes to a topic
	Subscribe(ctx context.Context, topic string, consumer string, handler MessageHandler) error
	// AsyncSubscribe subscribes to a topic and handles messages asynchronously
	AsyncSubscribe(ctx context.Context, topic string, consumer string, handler MessageHandler) error
}
    Stream is an interface for a stream
type StreamProvider ¶
StreamProvider is a function that returns a Stream
type Tags ¶
type Tags interface {
	// LogTags returns the tags for logging
	LogTags() map[string]any
	// WithMetadata adds metadata to the tags
	WithMetadata(md metadata.MD) Tags
	// WithMethod adds the grpc method to the tags
	WithMethod(method string) Tags
	// WithContextID adds the contextID to the tags
	WithContextID(contextID string) Tags
	// WithError adds the error to the tags
	WithError(err error) Tags
	// GetMetadata returns the metadata from the tags
	GetMetadata() (metadata.MD, bool)
	// GetMethod returns the grpc method from the tags
	GetMethod() (string, bool)
	// GetContextID returns the contextID from the tags
	GetContextID() (string, bool)
	// GetError returns the error from the tags
	GetError() (error, bool)
	// Set sets the value for the given key
	Set(key string, value any) Tags
	// Get returns the value for the given key
	Get(key string) (any, bool)
}
    Tags is an interface for tagging contexts