Documentation
¶
Index ¶
- Constants
- func AddSuffix(s string, suffix string) string
- func BuildRedisPool(URL string, poolSize int) (*redis.Pool, error)
- func CableDefaultErrorResolver(_ context.Context, event *Event, _ proto.Message) (string, error)
- func Clone(obj interface{}) interface{}
- func GenerateRandomString(n int) string
- func GetEnvOrBool(key string, defaultValue bool) bool
- func GetEnvOrFloat(key string, defaultValue float64) float64
- func GetEnvOrInt(key string, defaultValue int) int
- func GetEnvOrString(key string, defaultValue string) string
- func IsDevelopmentEnv() bool
- func IsProductionEnv() bool
- func IsTestEnv() bool
- func NewMessageFromEvent(event *Event) (*kafka.Message, error)
- func ProtoNameToTopic(protoName string) string
- func ProtoToName(msg proto.Message) string
- func ProtoToTopic(msg proto.Message) string
- type CableCourier
- type CableCourierOptions
- type CableCourierResolvers
- type CableGRPC
- type CableGRPCOptions
- type CableMessageEventHandler
- type CableMessageResolver
- type Component
- type Config
- type DatabaseConfig
- type Env
- type ErrorHandlingStrategy
- type Event
- type EventHandler
- type EventsWorker
- type EventsWorkerConfig
- type EventsWorkerOptions
- type GRPCConfig
- type GRPCServer
- type GRPCServerOptions
- type Gateway
- type GatewayOptions
- type HTTPServer
- type HTTPServerOptions
- type JobOptions
- type JobsEnqueuerConfig
- type JobsWorker
- type JobsWorkerOptions
- type KafkaConfig
- type KafkaConsumerConfig
- type KafkaProducerConfig
- type KafkaSASLConfig
- type MetricsConfig
- type MetricsServerComponent
- type MetricsServerComponentOption
- type OutboxConfig
- type OutboxCourier
- type OutboxCourierOptions
- type RedisConfig
- type SentryConfig
- type Service
- func (s *Service) CommitMessage(ctx context.Context, msg kafka.Message) ferr.FoundationError
- func (s *Service) DeleteOutboxEvents(ctx context.Context, tx pgx.Tx, maxID int64) ferr.FoundationError
- func (s *Service) GetComponent(name string) Component
- func (s *Service) GetJobsEnqueuer() *work.Enqueuer
- func (s *Service) GetKafkaConsumer() *kafka.Reader
- func (s *Service) GetKafkaProducer() *kafka.Writer
- func (s *Service) GetPostgreSQL() *pgxpool.Pool
- func (s *Service) GetRedis() *redis.Client
- func (s *Service) HandleError(err ferr.FoundationError, prefix string)
- func (s *Service) ListOutboxEvents(ctx context.Context, tx pgx.Tx, limit int32) ([]outboxrepo.FoundationOutboxEvent, ferr.FoundationError)
- func (s *Service) NewAndPublishEvent(ctx context.Context, msg proto.Message, key string, headers map[string]string, ...) ferr.FoundationError
- func (s *Service) PublishEvent(ctx context.Context, event *Event, tx pgx.Tx) ferr.FoundationError
- func (s *Service) Start(opts *StartOptions)
- func (s *Service) StartComponents(opts ...StartComponentsOption) error
- func (s *Service) StopComponents()
- func (s *Service) WithResponseTransaction(ctx context.Context, ...) (proto.Message, ferr.FoundationError)
- func (s *Service) WithTransaction(ctx context.Context, f func(tx pgx.Tx) ([]*Event, ferr.FoundationError)) ferr.FoundationError
- type SpinWorker
- type SpinWorkerOptions
- type StartComponentsOption
- type StartOptions
Constants ¶
const ( OutboxDefaultBatchSize = 100 OutboxDefaultInterval = time.Second * 1 )
const (
// Alphabet is the default alphabet used for string generation.
Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
)
const ( // GatewayDefaultTimeout is the default timeout for downstream services requests. GatewayDefaultTimeout = 30 * time.Second )
const (
MetricsServerComponentName = "metrics-server"
)
const (
SpinWorkerDefaultInterval = 5 * time.Millisecond
)
const Version = "0.2.1"
Variables ¶
This section is empty.
Functions ¶
func CableDefaultErrorResolver ¶
CableDefaultErrorResolver is a default resolver for errors that returns a stream name based on the user ID in the event headers.
func GenerateRandomString ¶
GenerateRandomString generates a random string of length n. Panics if an error occurs.
func GetEnvOrBool ¶
GetEnvOrBool returns the value of the environment variable named by the key argument, or defaultValue if there is no such variable set or it is empty.
func GetEnvOrFloat ¶
GetEnvOrFloat returns the value of the environment variable named by the key argument, or defaultValue if there is no such variable set or it is empty.
func GetEnvOrInt ¶
GetEnvOrInt returns the value of the environment variable named by the key argument, or defaultValue if there is no such variable set or it is empty.
func GetEnvOrString ¶
GetEnvOrString returns the value of the environment variable named by the key argument, or defaultValue if there is no such variable set or it is empty.
func IsDevelopmentEnv ¶
func IsDevelopmentEnv() bool
IsDevelopmentEnv returns true if the service is running in development mode.
func IsProductionEnv ¶
func IsProductionEnv() bool
IsProductionEnv returns true if the service is running in production mode.
func IsTestEnv ¶
func IsTestEnv() bool
IsTestEnv returns true if the service is running in test mode.
func NewMessageFromEvent ¶
NewMessageFromEvent creates a new Kafka message from a Foundation Outbox event
func ProtoNameToTopic ¶
TODO: extract these functions to a more appropriate place
func ProtoToName ¶
func ProtoToTopic ¶
Types ¶
type CableCourier ¶
type CableCourier struct {
*EventsWorker
Options *CableCourierOptions
}
CableCourier is a mode in which events are received from Kafka and published to Redis PubSub channels for AnyCable.
func InitCableCourier ¶
func InitCableCourier(name string) *CableCourier
InitCableCourier initializes a new CableCourier.
func (*CableCourier) Start ¶
func (c *CableCourier) Start(opts *CableCourierOptions)
Start runs a cable_courier worker using the given CableCourierOptions.
type CableCourierOptions ¶
type CableCourierOptions struct {
// Resolvers map protocol names to lists of CableMessageResolvers.
Resolvers map[proto.Message][]CableMessageResolver
// RedisChannel is the name of the Redis PubSub channel to publish events to.
RedisChannel string
}
CableCourierOptions contains configuration options to instantiate a CableCourier. It maps protocol names to their corresponding message resolvers.
func (*CableCourierOptions) EventHandlers ¶
func (opts *CableCourierOptions) EventHandlers(s *Service) map[proto.Message][]EventHandler
EventHandlers takes the resolvers defined in CableCourierOptions and wraps them into event handlers.
type CableCourierResolvers ¶
type CableCourierResolvers map[proto.Message][]CableMessageResolver
CableCourierResolvers maps proto.Message types to their corresponding resolvers.
type CableGRPC ¶
type CableGRPC struct {
*Service
Options *CableGRPCOptions
}
CableGRPC is a Foundation service in AnyCable gRPC Server mode.
func InitCableGRPC ¶
InitCableGRPC initializes a Foundation service in AnyCable gRPC Server mode.
func (*CableGRPC) Start ¶
func (s *CableGRPC) Start(opts *CableGRPCOptions)
Start runs the Foundation as an AnyCable-compartible gRPC server.
type CableGRPCOptions ¶
type CableGRPCOptions struct {
// GRPCServerOptions are the gRPC server options to use.
GRPCServerOptions []grpc.ServerOption
// StartComponentsOptions are the options to start the components.
StartComponentsOptions []StartComponentsOption
// Channels are the channels to use.
Channels map[string]cablegrpc.Channel
// WithAuthentication enables authentication.
WithAuthentication bool
// AuthenticationFunc is the function to use for authentication.
AuthenticationFunc cablegrpc.AuthenticationFunc
}
CableGRPCOptions are the options to start a Foundation service in gRPC Server mode.
func NewCableGRPCOptions ¶
func NewCableGRPCOptions() *CableGRPCOptions
type CableMessageEventHandler ¶
type CableMessageEventHandler struct {
// Resolver is used to resolve the stream name for a given event.
Resolver CableMessageResolver
Logger *logrus.Entry
Service *Service
RedisChannel string
}
CableMessageEventHandler is a concrete implementation of EventHandler that uses a CableMessageResolver to handle events.
func (*CableMessageEventHandler) Handle ¶
func (h *CableMessageEventHandler) Handle(ctx context.Context, event *Event, msg proto.Message) ([]*Event, ferr.FoundationError)
Handle uses the associated CableMessageResolver to determine the appropriate stream for the event and broadcasts the message to that stream.
type CableMessageResolver ¶
CableMessageResolver is a function that resolves the stream name for a given event.
type Component ¶
type Component interface {
// Health returns the health of the component
Health() error
// Name returns the name of the component
Name() string
// Start runs the component
Start() error
// Stop stops the component
Stop() error
}
Component describes an interface for all components in the Foundation framework. This could be an external service, a database, a cache, etc.
type Config ¶
type Config struct {
Database *DatabaseConfig
EventsWorker *EventsWorkerConfig
GRPC *GRPCConfig
Kafka *KafkaConfig
Metrics *MetricsConfig
Outbox *OutboxConfig
Redis *RedisConfig
Sentry *SentryConfig
JobsEnqueuer *JobsEnqueuerConfig
}
Config represents the configuration of a Service.
type DatabaseConfig ¶
DatabaseConfig represents the configuration of a PostgreSQL database.
type Env ¶
type Env string
Env represents the service environment name (development, production, etc).
type ErrorHandlingStrategy ¶
type ErrorHandlingStrategy int
ErrorHandlingStrategy defines the EventsWorker behavior when errors occur while handle event
const ( // Default strategy: commit the message and skip the event IgnoreError ErrorHandlingStrategy = iota // ShutdownOnError stops the worker on error ShutdownOnError )
type Event ¶
type Event struct {
Topic string
Key string
Payload []byte
ProtoName string
Headers map[string]string
CreatedAt time.Time
}
Event represents an event to be published to the outbox
func NewEventFromProto ¶
func NewEventFromProto(msg proto.Message, key string, headers map[string]string) (*Event, ferr.FoundationError)
NewEventFromProto creates a new event from a protobuf message
type EventHandler ¶
type EventHandler interface {
Handle(context.Context, *Event, proto.Message) ([]*Event, ferr.FoundationError)
}
EventHandler represents an event handler
type EventsWorker ¶
type EventsWorker struct {
*SpinWorker
// contains filtered or unexported fields
}
func InitEventsWorker ¶
func InitEventsWorker(name string) *EventsWorker
func (*EventsWorker) Start ¶
func (w *EventsWorker) Start(opts *EventsWorkerOptions)
Start runs the worker that handles events
type EventsWorkerConfig ¶
type EventsWorkerConfig struct {
// ErrorsTopic is the name of the Kafka topic to which errors from the
// events worker handlers should be published.
ErrorsTopic string
// DeliverErrors determines whether errors from events worker handlers
// should be published to the errors topic (and thus, delivered
// to originator, aka user) or not.
DeliverErrors bool
}
EventsWorkerConfig represents the configuration of an event bus.
type EventsWorkerOptions ¶
type EventsWorkerOptions struct {
Handlers map[proto.Message][]EventHandler
Topics []string
ModeName string
ErrorHandlingStrategy ErrorHandlingStrategy
StartComponentsOptions []StartComponentsOption
}
EventsWorkerOptions represents the options for starting an events worker
func (*EventsWorkerOptions) GetTopics ¶
func (opts *EventsWorkerOptions) GetTopics() []string
func (*EventsWorkerOptions) ProtoNamesToMessages ¶
func (opts *EventsWorkerOptions) ProtoNamesToMessages() map[string]proto.Message
type GRPCConfig ¶
type GRPCConfig struct {
TLSDir string
}
GRPCConfig represents the configuration of a gRPC server.
type GRPCServer ¶
type GRPCServer struct {
*Service
Options *GRPCServerOptions
}
GRPCServer represents a gRPC server mode Foundation service.
func InitGRPCServer ¶
func InitGRPCServer(name string) *GRPCServer
InitGRPCServer initializes a new Foundation service in gRPC Server mode.
func (*GRPCServer) ServiceFunc ¶
func (s *GRPCServer) ServiceFunc(ctx context.Context) error
func (*GRPCServer) Start ¶
func (s *GRPCServer) Start(opts *GRPCServerOptions)
Start initializes the Foundation service in gRPC server mode.
type GRPCServerOptions ¶
type GRPCServerOptions struct {
// RegisterFunc is a function that registers the gRPC server implementation.
RegisterFunc func(s *grpc.Server)
// GRPCServerOptions are the gRPC server options to use.
GRPCServerOptions []grpc.ServerOption
// StartComponentsOptions are the options to start the components.
StartComponentsOptions []StartComponentsOption
}
GRPCServerOptions are the options to start a Foundation service in gRPC Server mode.
func NewGRPCServerOptions ¶
func NewGRPCServerOptions() *GRPCServerOptions
type Gateway ¶
type Gateway struct {
*Service
Options *GatewayOptions
}
Gateway represents a gateway mode Foundation service.
func InitGateway ¶
InitGateway initializes a new Foundation service in Gateway mode.
func (*Gateway) Start ¶
func (s *Gateway) Start(opts *GatewayOptions)
Start runs the Foundation gateway.
type GatewayOptions ¶
type GatewayOptions struct {
// Services to register with the gateway
Services []*gateway.Service
// Timeout for downstream services requests (default: 30 seconds, if constructed with `NewGatewayOptions`)
Timeout time.Duration
// MuxOpts are additional grpc-gateway ServeMux options.
//
// Precedence:
// 1) Foundation applies its defaults first (incoming/outgoing header matchers, and the default marshaler option).
// 2) Then MuxOpts are applied in the order provided.
//
// This means MuxOpts can override Foundation defaults (e.g. add a later WithMarshalerOption).
MuxOpts []gwruntime.ServeMuxOption
// AuthenticationDetailsMiddleware is a middleware that populates the request context with authentication details.
AuthenticationDetailsMiddleware func(http.Handler) http.Handler
// WithAuthentication enables authentication for the gateway.
WithAuthentication bool
// AuthenticationExcept is a list of paths that should not be authenticated.
AuthenticationExcept []string
// Middleware is a list of middleware to apply to the gateway. The middleware is applied in the order it is defined.
Middleware []func(http.Handler) http.Handler
// StartComponentsOptions are the options to start the components.
StartComponentsOptions []StartComponentsOption
// CORSOptions are the options for CORS.
CORSOptions *gateway.CORSOptions
// MarshalOptions are used only for the default JSONPb marshaler when Marshaler is nil.
MarshalOptions protojson.MarshalOptions
// Marshaler overrides the default marshaler used by grpc-gateway.
//
// If nil, Foundation uses JSONPb configured with MarshalOptions.
// If non-nil, MarshalOptions is not applied automatically; include it in your custom marshaler if needed.
//
// Note: MuxOpts are applied after the default marshaler option, so a later
// runtime.WithMarshalerOption(...) in MuxOpts can override this as well.
Marshaler gwruntime.Marshaler
// SwaggerEndpoints is a list of endpoints to serve swagger JSON files.
SwaggerEndpoints []gateway.SwaggerEndpoint
}
GatewayOptions represents the options for starting the Foundation gateway.
func NewGatewayOptions ¶
func NewGatewayOptions() *GatewayOptions
NewGatewayOptions returns a new GatewayOptions with default values.
type HTTPServer ¶
type HTTPServer struct {
*Service
Options *HTTPServerOptions
}
HTTPServer represents a HTTP Server mode Foundation service.
func InitHTTPServer ¶
func InitHTTPServer(name string) *HTTPServer
InitHTTPServer initializes a new Foundation service in HTTP Server mode.
func (*HTTPServer) ServiceFunc ¶
func (s *HTTPServer) ServiceFunc(ctx context.Context) error
func (*HTTPServer) Start ¶
func (s *HTTPServer) Start(opts *HTTPServerOptions)
Start runs the Foundation service in HTTP Server mode.
type HTTPServerOptions ¶
type HTTPServerOptions struct {
// Handler is the HTTP handler to use.
Handler http.Handler
// StartComponentsOptions are the options to start the components.
StartComponentsOptions []StartComponentsOption
}
HTTPServerOptions are the options to start a Foundation service in HTTP Server mode.
func NewHTTPServerOptions ¶
func NewHTTPServerOptions() *HTTPServerOptions
type JobOptions ¶
type JobsEnqueuerConfig ¶
JobsEnqueuerConfig represents the configuration of a jobs enqueuer.
type JobsWorker ¶
type JobsWorker struct {
*Service
Options *JobsWorkerOptions
}
func InitJobsWorker ¶
func InitJobsWorker(name string) *JobsWorker
func (*JobsWorker) LoggingMiddleware ¶
func (w *JobsWorker) LoggingMiddleware(job *work.Job, next work.NextMiddlewareFunc) error
func (*JobsWorker) ServiceFunc ¶
func (w *JobsWorker) ServiceFunc(ctx context.Context) error
func (*JobsWorker) Start ¶
func (w *JobsWorker) Start(opts *JobsWorkerOptions)
Start runs the worker that handles jobs
type JobsWorkerOptions ¶
type JobsWorkerOptions struct {
// JobHandlers are the handlers to use for the jobs
Jobs map[string]JobOptions
// JobMiddlewares are the middlewares to use for all jobs
Middlewares []func(job *work.Job, next work.NextMiddlewareFunc) error
// Namespace is the redis namespace to use for the jobs
Namespace string
// Concurrency is the number of concurrent jobs to run
Concurrency int
// StartComponentsOptions are the options to start the components.
StartComponentsOptions []StartComponentsOption
}
JobsWorkerOptions represents the options for starting a jobs worker
func NewJobsWorkerOptions ¶
func NewJobsWorkerOptions() *JobsWorkerOptions
type KafkaConfig ¶
type KafkaConfig struct {
Brokers []string
SASL *KafkaSASLConfig
Consumer *KafkaConsumerConfig
Producer *KafkaProducerConfig
TLSDir string
}
KafkaConfig represents the configuration of a Kafka client.
type KafkaConsumerConfig ¶
KafkaConsumerConfig represents the configuration of a Kafka consumer.
type KafkaProducerConfig ¶
KafkaProducerConfig represents the configuration of a Kafka producer.
type KafkaSASLConfig ¶
KafkaSASLConfig represents the configuration of a Kafka consumer.
type MetricsConfig ¶
MetricsConfig represents the configuration of a metrics server.
type MetricsServerComponent ¶
type MetricsServerComponent struct {
// contains filtered or unexported fields
}
func NewMetricsServerComponent ¶
func NewMetricsServerComponent(opts ...MetricsServerComponentOption) *MetricsServerComponent
func (*MetricsServerComponent) Health ¶
func (c *MetricsServerComponent) Health() error
Health implements the Component interface.
func (*MetricsServerComponent) Name ¶
func (c *MetricsServerComponent) Name() string
Name implements the Component interface.
func (*MetricsServerComponent) Start ¶
func (c *MetricsServerComponent) Start() error
Start implements the Component interface.
func (*MetricsServerComponent) Stop ¶
func (c *MetricsServerComponent) Stop() error
Stop implements the Component interface.
type MetricsServerComponentOption ¶
type MetricsServerComponentOption func(*MetricsServerComponent)
func WithMetricsServerHealthHandler ¶
func WithMetricsServerHealthHandler(handler http.HandlerFunc) MetricsServerComponentOption
WithMetricsServerHealthHandler sets the health handler for the MetricsServer component.
func WithMetricsServerLogger ¶
func WithMetricsServerLogger(logger *logrus.Entry) MetricsServerComponentOption
WithMetricsServerLogger sets the logger for the MetricsServer component.
func WithMetricsServerPort ¶
func WithMetricsServerPort(port int) MetricsServerComponentOption
WithMetricsServerPort sets the port for the MetricsServer component.
type OutboxConfig ¶
type OutboxConfig struct {
Enabled bool
}
OutboxConfig represents the configuration of an outbox.
type OutboxCourier ¶
type OutboxCourier struct {
*SpinWorker
}
func InitOutboxCourier ¶
func InitOutboxCourier(name string) *OutboxCourier
func (*OutboxCourier) Start ¶
func (o *OutboxCourier) Start(outboxOpts *OutboxCourierOptions)
Start runs the outbox courier
type OutboxCourierOptions ¶
type OutboxCourierOptions struct {
Interval time.Duration
BatchSize int32
ModeName string
StartComponentsOptions []StartComponentsOption
}
OutboxCourierOptions represents the options for starting an outbox courier
func NewOutboxCourierOptions ¶
func NewOutboxCourierOptions() *OutboxCourierOptions
type RedisConfig ¶
RedisConfig represents the configuration of a Redis client.
type SentryConfig ¶
SentryConfig represents the configuration of a Sentry client.
type Service ¶
type Service struct {
Name string
Config *Config
Components []Component
ModeName string
Logger *logrus.Entry
// contains filtered or unexported fields
}
Service represents a single microservice - part of the bigger Foundation-based application, which implements an isolated domain of the application logic.
func (*Service) CommitMessage ¶
CommitMessage tries to commit a Kafka message using the service's KafkaConsumer. If the commit operation fails, it retries up to three times with a one-second pause between retries. If all attempts fail, the function returns the last occurred error.
func (*Service) DeleteOutboxEvents ¶
func (s *Service) DeleteOutboxEvents(ctx context.Context, tx pgx.Tx, maxID int64) ferr.FoundationError
DeleteOutboxEvents deletes outbox events up to (and including) the given ID.
func (*Service) GetComponent ¶
GetComponent returns the component with the given name.
func (*Service) GetJobsEnqueuer ¶
func (*Service) GetKafkaConsumer ¶
func (*Service) GetKafkaProducer ¶
func (*Service) GetPostgreSQL ¶
func (*Service) HandleError ¶
func (s *Service) HandleError(err ferr.FoundationError, prefix string)
func (*Service) ListOutboxEvents ¶
func (s *Service) ListOutboxEvents(ctx context.Context, tx pgx.Tx, limit int32) ([]outboxrepo.FoundationOutboxEvent, ferr.FoundationError)
ListOutboxEvents returns a list of outbox events in the order they were created.
func (*Service) NewAndPublishEvent ¶
func (s *Service) NewAndPublishEvent(ctx context.Context, msg proto.Message, key string, headers map[string]string, tx pgx.Tx) ferr.FoundationError
NewAndPublishEvent creates a new event and publishes it to the outbox within a transaction
func (*Service) PublishEvent ¶
PublishEvent publishes an event to the outbox, starting a new transaction, or straight to the Kafka topic if `OUTBOX_ENABLED` is not set.
func (*Service) Start ¶
func (s *Service) Start(opts *StartOptions)
Start runs the Foundation service.
func (*Service) StartComponents ¶
func (s *Service) StartComponents(opts ...StartComponentsOption) error
StartComponents starts the default Foundation service components.
func (*Service) StopComponents ¶
func (s *Service) StopComponents()
StopComponents stops the default Foundation service components.
func (*Service) WithResponseTransaction ¶
func (s *Service) WithResponseTransaction(ctx context.Context, f func(tx pgx.Tx) (proto.Message, []*Event, ferr.FoundationError)) (proto.Message, ferr.FoundationError)
WithResponseTransaction executes the given function in a transaction. If the function returns an event, it will be published. If the function returns a response, it will be returned.
func (*Service) WithTransaction ¶
func (s *Service) WithTransaction(ctx context.Context, f func(tx pgx.Tx) ([]*Event, ferr.FoundationError)) ferr.FoundationError
WithTransaction executes the given function in a transaction. If the function returns an event, it will be published.
type SpinWorker ¶
type SpinWorker struct {
*Service
Options *SpinWorkerOptions
}
SpinWorker is a type of Foundation service.
func InitSpinWorker ¶
func InitSpinWorker(name string) *SpinWorker
InitSpinWorker initializes a new Foundation service in worker mode.
func (*SpinWorker) ServiceFunc ¶
func (sw *SpinWorker) ServiceFunc(ctx context.Context) error
ServiceFunc is the default service function for a worker.
func (*SpinWorker) Start ¶
func (sw *SpinWorker) Start(opts *SpinWorkerOptions)
Start runs the Foundation worker
type SpinWorkerOptions ¶
type SpinWorkerOptions struct {
// ProcessFunc is the function to execute in the loop iteration.
ProcessFunc func(ctx context.Context) ferr.FoundationError
// Interval is the interval to run the iteration function. If function execution took less time than the interval,
// the worker will sleep for the remaining time of the interval. Otherwise, the function will be executed again
// immediately. Default: 5ms, if constructed with NewSpinWorkerOptions().
Interval time.Duration
// ModeName is the name of the worker mode. It will be used in the startup log message. Default: "spin_worker".
// Meant to be used in custom modes based on the `spin_worker` mode.
ModeName string
StartComponentsOptions []StartComponentsOption
}
SpinWorkerOptions are the options to start a Foundation service in worker mode.
func NewSpinWorkerOptions ¶
func NewSpinWorkerOptions() *SpinWorkerOptions
NewSpinWorkerOptions returns a new SpinWorkerOptions instance with default values.
type StartComponentsOption ¶
type StartComponentsOption func(*Service)
StartComponentsOption is an option to `StartComponents`.
func WithJobsEnqueuer ¶
func WithJobsEnqueuer() StartComponentsOption
WithJobsEnqueuer sets the jobs enqueuer enabled flag.
func WithKafkaConsumer ¶
func WithKafkaConsumer() StartComponentsOption
WithKafkaConsumer sets the Kafka consumer enabled flag.
func WithKafkaConsumerTopics ¶
func WithKafkaConsumerTopics(topics ...string) StartComponentsOption
WithKafkaConsumerTopics sets the Kafka consumer topics.
func WithKafkaProducer ¶
func WithKafkaProducer() StartComponentsOption
WithKafkaProducer sets the Kafka producer enabled flag.
type StartOptions ¶
type StartOptions struct {
ModeName string
StartComponentsOptions []StartComponentsOption
ServiceFunc func(ctx context.Context) error
}
Source Files
¶
- cable_courier.go
- cable_grpc.go
- component.go
- env.go
- errors.go
- events_worker.go
- foundation.go
- gateway.go
- grpc_server.go
- health.go
- helpers.go
- http_server.go
- jobs_helpers.go
- jobs_worker.go
- kafka_helpers.go
- logging.go
- metrics_server.go
- otel.go
- outbox.go
- outbox_courier.go
- postgresql_helpers.go
- rand.go
- redis_helpers.go
- spin_worker.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cable
|
|
|
cmd
|
|
|
foundation
command
|
|
|
examples
|
|
|
clubchat/protos/chats
Package chats is a reverse proxy.
|
Package chats is a reverse proxy. |
|
clubchat/chats
module
|
|
|
clubchat/clubchat
module
|
|
|
internal
|
|