bootstrap

package
v3.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const ApplicationName = "transaction"
View Source
const ConsumerLockTTL = 1500 // 25 minutes in seconds
View Source
const CronTimeToRun = 30 * time.Minute
View Source
const MaxWorkers = 100
View Source
const MessageTimeOfLife = 30

Variables

This section is empty.

Functions

This section is empty.

Types

type BalanceSyncWorker added in v3.4.1

type BalanceSyncWorker struct {
	// contains filtered or unexported fields
}

BalanceSyncWorker continuously processes keys scheduled for pre-expiry actions. Ensures that the balance is synced before the key expires.

func NewBalanceSyncWorker added in v3.4.1

func NewBalanceSyncWorker(conn *libRedis.RedisConnection, logger libLog.Logger, useCase *command.UseCase, maxWorkers int) *BalanceSyncWorker

func (*BalanceSyncWorker) Run added in v3.4.1

type Config

type Config struct {
	EnvName  string `env:"ENV_NAME"`
	LogLevel string `env:"LOG_LEVEL"`

	// Server address - prefixed for unified ledger deployment
	PrefixedServerAddress string `env:"SERVER_ADDRESS_TRANSACTION"`
	ServerAddress         string `env:"SERVER_ADDRESS"`

	// PostgreSQL Primary - prefixed vars for unified ledger deployment
	PrefixedPrimaryDBHost     string `env:"DB_TRANSACTION_HOST"`
	PrefixedPrimaryDBUser     string `env:"DB_TRANSACTION_USER"`
	PrefixedPrimaryDBPassword string `env:"DB_TRANSACTION_PASSWORD"`
	PrefixedPrimaryDBName     string `env:"DB_TRANSACTION_NAME"`
	PrefixedPrimaryDBPort     string `env:"DB_TRANSACTION_PORT"`
	PrefixedPrimaryDBSSLMode  string `env:"DB_TRANSACTION_SSLMODE"`

	// PostgreSQL Primary - fallback vars for standalone deployment
	PrimaryDBHost     string `env:"DB_HOST"`
	PrimaryDBUser     string `env:"DB_USER"`
	PrimaryDBPassword string `env:"DB_PASSWORD"`
	PrimaryDBName     string `env:"DB_NAME"`
	PrimaryDBPort     string `env:"DB_PORT"`
	PrimaryDBSSLMode  string `env:"DB_SSLMODE"`

	// PostgreSQL Replica - prefixed vars for unified ledger deployment
	PrefixedReplicaDBHost     string `env:"DB_TRANSACTION_REPLICA_HOST"`
	PrefixedReplicaDBUser     string `env:"DB_TRANSACTION_REPLICA_USER"`
	PrefixedReplicaDBPassword string `env:"DB_TRANSACTION_REPLICA_PASSWORD"`
	PrefixedReplicaDBName     string `env:"DB_TRANSACTION_REPLICA_NAME"`
	PrefixedReplicaDBPort     string `env:"DB_TRANSACTION_REPLICA_PORT"`
	PrefixedReplicaDBSSLMode  string `env:"DB_TRANSACTION_REPLICA_SSLMODE"`

	// PostgreSQL Replica - fallback vars for standalone deployment
	ReplicaDBHost     string `env:"DB_REPLICA_HOST"`
	ReplicaDBUser     string `env:"DB_REPLICA_USER"`
	ReplicaDBPassword string `env:"DB_REPLICA_PASSWORD"`
	ReplicaDBName     string `env:"DB_REPLICA_NAME"`
	ReplicaDBPort     string `env:"DB_REPLICA_PORT"`
	ReplicaDBSSLMode  string `env:"DB_REPLICA_SSLMODE"`

	// PostgreSQL connection pool - prefixed with fallback
	PrefixedMaxOpenConnections int `env:"DB_TRANSACTION_MAX_OPEN_CONNS"`
	PrefixedMaxIdleConnections int `env:"DB_TRANSACTION_MAX_IDLE_CONNS"`
	MaxOpenConnections         int `env:"DB_MAX_OPEN_CONNS"`
	MaxIdleConnections         int `env:"DB_MAX_IDLE_CONNS"`

	// MongoDB - prefixed vars for unified ledger deployment
	PrefixedMongoURI          string `env:"MONGO_TRANSACTION_URI"`
	PrefixedMongoDBHost       string `env:"MONGO_TRANSACTION_HOST"`
	PrefixedMongoDBName       string `env:"MONGO_TRANSACTION_NAME"`
	PrefixedMongoDBUser       string `env:"MONGO_TRANSACTION_USER"`
	PrefixedMongoDBPassword   string `env:"MONGO_TRANSACTION_PASSWORD"`
	PrefixedMongoDBPort       string `env:"MONGO_TRANSACTION_PORT"`
	PrefixedMongoDBParameters string `env:"MONGO_TRANSACTION_PARAMETERS"`
	PrefixedMaxPoolSize       int    `env:"MONGO_TRANSACTION_MAX_POOL_SIZE"`

	// MongoDB - fallback vars for standalone deployment
	MongoURI                     string `env:"MONGO_URI"`
	MongoDBHost                  string `env:"MONGO_HOST"`
	MongoDBName                  string `env:"MONGO_NAME"`
	MongoDBUser                  string `env:"MONGO_USER"`
	MongoDBPassword              string `env:"MONGO_PASSWORD"`
	MongoDBPort                  string `env:"MONGO_PORT"`
	MongoDBParameters            string `env:"MONGO_PARAMETERS"`
	MaxPoolSize                  int    `env:"MONGO_MAX_POOL_SIZE"`
	CasdoorAddress               string `env:"CASDOOR_ADDRESS"`
	CasdoorClientID              string `env:"CASDOOR_CLIENT_ID"`
	CasdoorClientSecret          string `env:"CASDOOR_CLIENT_SECRET"`
	CasdoorOrganizationName      string `env:"CASDOOR_ORGANIZATION_NAME"`
	CasdoorApplicationName       string `env:"CASDOOR_APPLICATION_NAME"`
	CasdoorModelName             string `env:"CASDOOR_MODEL_NAME"`
	JWKAddress                   string `env:"CASDOOR_JWK_ADDRESS"`
	RabbitURI                    string `env:"RABBITMQ_URI"`
	RabbitMQHost                 string `env:"RABBITMQ_HOST"`
	RabbitMQPortHost             string `env:"RABBITMQ_PORT_HOST"`
	RabbitMQPortAMQP             string `env:"RABBITMQ_PORT_AMQP"`
	RabbitMQUser                 string `env:"RABBITMQ_DEFAULT_USER"`
	RabbitMQPass                 string `env:"RABBITMQ_DEFAULT_PASS"`
	RabbitMQConsumerUser         string `env:"RABBITMQ_CONSUMER_USER"`
	RabbitMQConsumerPass         string `env:"RABBITMQ_CONSUMER_PASS"`
	RabbitMQBalanceCreateQueue   string `env:"RABBITMQ_BALANCE_CREATE_QUEUE"`
	RabbitMQNumbersOfWorkers     int    `env:"RABBITMQ_NUMBERS_OF_WORKERS"`
	RabbitMQNumbersOfPrefetch    int    `env:"RABBITMQ_NUMBERS_OF_PREFETCH"`
	RabbitMQHealthCheckURL       string `env:"RABBITMQ_HEALTH_CHECK_URL"`
	OtelServiceName              string `env:"OTEL_RESOURCE_SERVICE_NAME"`
	OtelLibraryName              string `env:"OTEL_LIBRARY_NAME"`
	OtelServiceVersion           string `env:"OTEL_RESOURCE_SERVICE_VERSION"`
	OtelDeploymentEnv            string `env:"OTEL_RESOURCE_DEPLOYMENT_ENVIRONMENT"`
	OtelColExporterEndpoint      string `env:"OTEL_EXPORTER_OTLP_ENDPOINT"`
	EnableTelemetry              bool   `env:"ENABLE_TELEMETRY"`
	RedisHost                    string `env:"REDIS_HOST"`
	RedisMasterName              string `env:"REDIS_MASTER_NAME" default:""`
	RedisPassword                string `env:"REDIS_PASSWORD"`
	RedisDB                      int    `env:"REDIS_DB" default:"0"`
	RedisProtocol                int    `env:"REDIS_DB" default:"3"`
	RedisTLS                     bool   `env:"REDIS_TLS" default:"false"`
	RedisCACert                  string `env:"REDIS_CA_CERT"`
	RedisUseGCPIAM               bool   `env:"REDIS_USE_GCP_IAM" default:"false"`
	RedisServiceAccount          string `env:"REDIS_SERVICE_ACCOUNT" default:""`
	GoogleApplicationCredentials string `env:"GOOGLE_APPLICATION_CREDENTIALS" default:""`
	RedisTokenLifeTime           int    `env:"REDIS_TOKEN_LIFETIME" default:"60"`
	RedisTokenRefreshDuration    int    `env:"REDIS_TOKEN_REFRESH_DURATION" default:"45"`
	RedisPoolSize                int    `env:"REDIS_POOL_SIZE" default:"10"`
	RedisMinIdleConns            int    `env:"REDIS_MIN_IDLE_CONNS" default:"0"`
	RedisReadTimeout             int    `env:"REDIS_READ_TIMEOUT" default:"3"`
	RedisWriteTimeout            int    `env:"REDIS_WRITE_TIMEOUT" default:"3"`
	RedisDialTimeout             int    `env:"REDIS_DIAL_TIMEOUT" default:"5"`
	RedisPoolTimeout             int    `env:"REDIS_POOL_TIMEOUT" default:"2"`
	RedisMaxRetries              int    `env:"REDIS_MAX_RETRIES" default:"3"`
	RedisMinRetryBackoff         int    `env:"REDIS_MIN_RETRY_BACKOFF" default:"8"`
	RedisMaxRetryBackoff         int    `env:"REDIS_MAX_RETRY_BACKOFF" default:"1"`
	AuthEnabled                  bool   `env:"PLUGIN_AUTH_ENABLED"`
	AuthHost                     string `env:"PLUGIN_AUTH_HOST"`
	ProtoAddress                 string `env:"PROTO_ADDRESS"`
	BalanceSyncWorkerEnabled     bool   `env:"BALANCE_SYNC_WORKER_ENABLED" default:"true"`
	BalanceSyncMaxWorkers        int    `env:"BALANCE_SYNC_MAX_WORKERS"`
}

Config is the top level configuration struct for the entire application. Supports prefixed env vars (DB_TRANSACTION_*) with fallback to non-prefixed (DB_*) for backward compatibility.

type MultiQueueConsumer

type MultiQueueConsumer struct {
	UseCase *command.UseCase
	// contains filtered or unexported fields
}

MultiQueueConsumer represents a multi-queue consumer.

func NewMultiQueueConsumer

func NewMultiQueueConsumer(routes *rabbitmq.ConsumerRoutes, useCase *command.UseCase) *MultiQueueConsumer

NewMultiQueueConsumer create a new instance of MultiQueueConsumer.

func (*MultiQueueConsumer) Run

Run starts consumers for all registered queues.

type Options added in v3.5.0

type Options struct {
	// Logger allows callers to provide a pre-configured logger, avoiding double
	// initialization when the cmd/app wants to handle bootstrap errors.
	Logger libLog.Logger
}

Options contains optional dependencies that can be injected by callers.

type Ports added in v3.5.0

type Ports struct {
	// BalancePort is exposed for use by onboarding module in unified ledger mode.
	// This is the transaction UseCase which implements BalancePort directly.
	BalancePort mbootstrap.BalancePort

	// MetadataPort is the MongoDB metadata repository for direct access in unified ledger mode.
	MetadataPort mbootstrap.MetadataIndexRepository
}

Ports groups all external interface dependencies for the transaction service. These are the "ports" in hexagonal architecture that connect to external systems or are exposed to other modules (like unified ledger mode).

type RedisQueueConsumer added in v3.3.0

type RedisQueueConsumer struct {
	Logger             libLog.Logger
	TransactionHandler in.TransactionHandler
}

func NewRedisQueueConsumer added in v3.3.0

func NewRedisQueueConsumer(logger libLog.Logger, handler in.TransactionHandler) *RedisQueueConsumer

func (*RedisQueueConsumer) Run added in v3.3.0

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the http server for Ledger services.

func NewServer

func NewServer(cfg *Config, app *fiber.App, logger libLog.Logger, telemetry *libOpentelemetry.Telemetry) *Server

NewServer creates an instance of Server.

func (*Server) Run

func (s *Server) Run(l *libCommons.Launcher) error

Run runs the server.

func (*Server) ServerAddress

func (s *Server) ServerAddress() string

ServerAddress returns is a convenience method to return the server address.

type ServerGRPC added in v3.4.1

type ServerGRPC struct {
	libLog.Logger
	libOpentelemetry.Telemetry
	// contains filtered or unexported fields
}

func NewServerGRPC added in v3.4.1

func NewServerGRPC(cfg *Config, server *grpc.Server, logger libLog.Logger, telemetry *libOpentelemetry.Telemetry) *ServerGRPC

func (*ServerGRPC) ProtoAddress added in v3.4.1

func (sgrpc *ServerGRPC) ProtoAddress() string

ProtoAddress returns is a convenience method to return the proto server address.

func (*ServerGRPC) Run added in v3.4.1

func (sgrpc *ServerGRPC) Run(l *libCommons.Launcher) error

type Service

type Service struct {
	*Server
	*ServerGRPC
	*MultiQueueConsumer
	*RedisQueueConsumer
	*BalanceSyncWorker
	BalanceSyncWorkerEnabled bool
	libLog.Logger

	// Ports groups all external interface dependencies.
	Ports Ports
	// contains filtered or unexported fields
}

Service is the application glue where we put all top level components to be used.

func InitServers

func InitServers() (*Service, error)

InitServers initiate http and grpc servers.

func InitServersWithOptions added in v3.5.0

func InitServersWithOptions(opts *Options) (*Service, error)

InitServersWithOptions initiates http and grpc servers with optional dependency injection.

func (*Service) GetBalancePort added in v3.5.0

func (app *Service) GetBalancePort() mbootstrap.BalancePort

GetBalancePort returns the balance port for use by onboarding in unified mode. This allows direct in-process calls instead of gRPC. The returned BalancePort is the transaction UseCase itself, which implements the interface directly - no intermediate adapters needed.

func (*Service) GetMetadataIndexPort added in v3.5.0

func (app *Service) GetMetadataIndexPort() mbootstrap.MetadataIndexRepository

GetMetadataIndexPort returns the metadata index port for use by ledger in unified mode. This allows direct in-process calls for metadata index operations.

func (*Service) GetRouteRegistrar added in v3.5.0

func (app *Service) GetRouteRegistrar() func(*fiber.App)

GetRouteRegistrar returns a function that registers transaction routes to an existing Fiber app. This is used by the unified ledger server to consolidate all routes in a single port.

func (*Service) GetRunnables added in v3.5.0

func (app *Service) GetRunnables() []mbootstrap.RunnableConfig

GetRunnables returns all runnable components for composition in unified deployment. Implements mbootstrap.Service interface. In unified mode, gRPC server is excluded since communication is done in-process.

func (*Service) GetRunnablesWithOptions added in v3.5.0

func (app *Service) GetRunnablesWithOptions(excludeGRPC bool) []mbootstrap.RunnableConfig

GetRunnablesWithOptions returns runnable components with optional gRPC exclusion. When excludeGRPC is true, the gRPC server is not included (used in unified ledger mode).

func (*Service) Run

func (app *Service) Run()

Run starts the application. This is the only necessary code to run an app in main.go

Jump to

Keyboard shortcuts

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