providers

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

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

func WithTags

func WithTags(ctx context.Context, tags Tags) context.Context

WithTags adds tags to the context

Types

type All

type All struct {
	Logger   Logger
	Database Database
	Cache    Cache
	Stream   Stream
	Metrics  Metrics
}

All is a struct that contains all providers

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

type CacheProvider func(ctx context.Context, config *viper.Viper) (Cache, error)

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

type ContextTaggerFunc func(ctx context.Context) Tags

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

type ContextTaggerProvider func(ctx context.Context, cfg *viper.Viper) (ContextTagger, error)

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

type DatabaseProvider func(ctx context.Context, config *viper.Viper) (Database, error)

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

type LoggingProvider func(ctx context.Context, cfg *viper.Viper) (Logger, error)

LoggingProvider is a function that returns a Logger

type MessageHandler

type MessageHandler func(ctx context.Context, message map[string]any) bool

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

type MetricsProvider func(ctx context.Context, cfg *viper.Viper) (Metrics, error)

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

type StreamProvider func(ctx context.Context, cfg *viper.Viper) (Stream, error)

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

func GetTags

func GetTags(ctx context.Context) (Tags, bool)

GetTags returns the tags from the context

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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