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 Card
- type Charge
- type ContextTagger
- type ContextTaggerFunc
- type ContextTaggerProvider
- type Customer
- type Database
- type DatabaseProvider
- type Email
- type EmailProvider
- type Emailer
- type Logger
- type LoggingProvider
- type MessageHandler
- type Metrics
- type MetricsProvider
- type PaymentProcessor
- type PaymentProcessorProvider
- type Storage
- 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 All ¶
type All struct { Logger Logger Database Database Cache Cache Stream Stream Metrics Metrics Email Emailer PaymentProcessor PaymentProcessor Storage Storage }
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 ¶
CacheProvider is a function that returns a Cache
type Card ¶ added in v0.9.1
type Card struct { ID string `json:"id"` Brand string `json:"brand"` Last4 string `json:"last4"` ExpM int64 `json:"exp_month"` ExpY int64 `json:"exp_year"` IsDefault bool `json:"is_default"` CreatedAt time.Time `json:"created_at"` }
Card is a struct for a customer's card
type Charge ¶ added in v0.9.1
type Charge struct { ID string `json:"id"` CustomerID string `json:"customer_id"` CardID string `json:"card_id"` Amount int64 `json:"amount"` Description string `json:"description"` Status string `json:"status"` CreatedAt time.Time `json:"created_at"` }
Charge is a struct for charging a customer
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 Customer ¶ added in v0.9.1
type Customer struct { ID string `json:"id"` Name string `json:"name"` Phone string `json:"phone"` Email string `json:"email"` Description string `json:"description"` DefaultCardID string `json:"default_card_id"` Metadata map[string]string `json:"metadata"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Customer is a struct for creating a customer
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 Email ¶ added in v0.9.1
type Email struct { From string `json:"from"` To []string `json:"to"` Subject string `json:"subject"` Body string `json:"body"` ContentType string `json:"content_type"` }
Email is a struct for sending emails
type EmailProvider ¶ added in v0.9.1
EmailProvider is a function that returns an Emailer implementation
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 PaymentProcessor ¶ added in v0.9.1
type PaymentProcessor interface { // CreateCustomer creates a customer CreateCustomer(ctx context.Context, charge *Customer) (*Customer, error) // UpdateCustomer updates a customer UpdateCustomer(ctx context.Context, charge *Customer) (*Customer, error) // GetCustomer gets a customer GetCustomer(ctx context.Context, id string) (*Customer, error) // DeleteCustomer deletes a customer DeleteCustomer(ctx context.Context, id string) error // ListCustomers lists customers ListCustomers(ctx context.Context, after string, limit int64) ([]*Customer, error) // CreateCard creates a card for a customer CreateCard(ctx context.Context, customerID string, token string) (*Card, error) // GetCard gets a card for a customer GetCard(ctx context.Context, customerID string, cardID string) (*Card, error) // DeleteCard deletes a card for a customer DeleteCard(ctx context.Context, customerID string, cardID string) error // ListCards lists cards for a customer ListCards(ctx context.Context, customerID string) ([]*Card, error) // CreateCharge creates a charge CreateCharge(ctx context.Context, charge *Charge) (*Charge, error) // GetCharge gets a charge GetCharge(ctx context.Context, id string) (*Charge, error) // ListCharges lists charges ListCharges(ctx context.Context, customerID, after string, limit int64) ([]*Charge, error) }
PaymentProcessor is a function that returns a PaymentProcessor implementation
type PaymentProcessorProvider ¶ added in v0.9.1
type PaymentProcessorProvider func(ctx context.Context, config *viper.Viper) (PaymentProcessor, error)
PaymentProcessorProvider is a function that returns a PaymentProcessor implementation
type Storage ¶ added in v0.9.4
type Storage interface { // WriteFile writes a file to the storage provider WriteFile(ctx context.Context, path string, r io.ReadSeeker) error // ReadFile reads a file from the storage provider ReadFile(ctx context.Context, path string, w io.Writer) error // DeleteFile deletes a file DeleteFile(ctx context.Context, path string) error }
Storage is an interface for a file storage provider
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