config

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package config is the single source of application configuration. It reads the environment once at startup, validates it, and hands back a typed Config that the rest of the platform passes around instead of touching os.Getenv directly.

New is the only entry point. It loads every variable, fails fast if a required one is missing, applies defaults for the optional ones, and validates the Stellar material — treasury, admin, and server secret keys, the USDC issuer, and the contract ID are parsed through the SDK so a malformed value is caught at boot rather than on first use. The network passphrase is derived from the environment: development runs against the test network, everything else against the public network.

Layout

Config is composed of one sub-config per concern — Postgres, Redis, Server, Stellar, Payments, Mobile, and Auth — and Payments nests one config per provider. Sub-configs carry the small helpers that turn raw fields into usable values: PostgresConfig.DSN, RedisConfig.Addr, ServerConfig's listen addresses, StellarConfig.NewRpcClient, and so on. Some values are shared or derived rather than read twice — the MoneyGram anchor reuses the Stellar network passphrase and falls back to the global USDC issuer when its own is unset.

Provider configuration

MoneyGram is the default cash-pickup anchor and is always wired, so it has its own Validate to confirm the anchor fields are present. Its REST API credentials (for FX rates) are optional; HasRESTCredentials reports whether they are populated, letting callers fall back to another provider's rates when they are not.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfricasTalkingConfig

type AfricasTalkingConfig struct {
	Username  string
	APIKey    string
	BaseURL   string
	SenderID  string // from AT_SENDER_ID (alphanumeric or shortcode)
	Shortcode string // from AT_SHORTCODE (numeric shortcode)

	// HTTPTimeout bounds a single SMS send attempt. From AT_HTTP_TIMEOUT
	// (seconds); zero when unset, leaving the adapter to apply its default.
	HTTPTimeout time.Duration
}

AfricasTalkingConfig holds all SMS/USSD-related configuration for Africa's Talking

func (*AfricasTalkingConfig) ResolveSenderID

func (c *AfricasTalkingConfig) ResolveSenderID() string

ResolveSenderID returns the sender ID to use for SMS. Priority: SenderID > Shortcode > "" (AT defaults to AFRICASTKNG).

type AuthConfig

type AuthConfig struct {
	JWTSecret           string
	JWTExpiration       time.Duration
	JWTRefreshWindow    time.Duration
	ChallengeExpiration time.Duration
	PINLockoutDuration  time.Duration // from PIN_LOCKOUT_SECONDS (default 900 = 15min)
}

type Config

type Config struct {
	Postgres  PostgresConfig
	Redis     RedisConfig
	Server    ServerConfig
	Stellar   StellarConfig
	Payments  PaymentsConfig
	Mobile    MobileConfig
	Auth      AuthConfig
	Shortener ShortenerConfig
}

Config holds all configuration for the application, composed of sub-configs.

func New

func New() (*Config, error)

New loads and returns a new Config struct populated from environment variables.

type FonbnkConfig

type FonbnkConfig struct {
	ClientID     string
	ClientSecret string
	BaseURL      string
}

FonbnkConfig holds all Fonbnk-related configuration

type MobileConfig

type MobileConfig struct {
	AfricasTalking AfricasTalkingConfig
	// SessionTimeout is the Redis TTL for a USSD session, refreshed on each
	// request. From USSD_SESSION_TIMEOUT (seconds); defaults to 5 minutes.
	SessionTimeout time.Duration
}

MobileConfig holds all mobile-related configuration

type MoneyGramConfig added in v1.0.0

type MoneyGramConfig struct {
	// SEP-1 / 9 / 10 / 24 — Stellar anchor protocol
	HomeDomain        string // e.g. "stellar.moneygram.com"
	ServerSigningKey  string // pinned from TOML, validated at boot
	NetworkPassphrase string // matches StellarConfig.NetworkPassphrase
	USDCIssuer        string // matches StellarConfig.USDCIssuer
	TransferServerURL string // override, otherwise resolved from TOML

	// REST API — OAuth 2.0 client_credentials (FX rates)
	ClientID     string
	ClientSecret string
	OAuthURL     string // token endpoint
	FXRateURL    string // GET /fx-rate/v1/rates

	// Entry-rate buffers applied by the FX orchestrator, as fractions
	// (0.01 = 1 %). Nil leaves the orchestrator's own defaults in place;
	// an explicit 0 quotes raw source rates with no buffer at all.
	// From MONEYGRAM_FX_ENTRY_BUFFER_PCT and
	// MONEYGRAM_FX_ENTRY_BUFFER_PCT_FALLBACK.
	FXEntryBufferPct         *float64
	FXEntryBufferPctFallback *float64

	// Custodial wallets. AuthSecret co-signs SEP-10; FundsSecret is the SEP-24
	// account and USDC send source. Both default to TREASURY_SECRET_KEY.
	AuthSecret  string
	FundsSecret string

	// Poller cadence. Zero leaves mgpoller.DefaultConfig's value in place
	// rather than config duplicating the defaults.
	PollInterval            time.Duration // MONEYGRAM_POLL_INTERVAL (seconds)
	PollMaxBatch            int           // MONEYGRAM_POLL_MAX_BATCH
	RefundSettleMaxAttempts int           // MONEYGRAM_REFUND_MAX_ATTEMPTS
}

MoneyGramConfig holds all MoneyGram-related configuration.

MoneyGram acts as both a Stellar SEP-1/9/10/24 anchor (for the cash-pickup off-ramp flow) and a REST API provider (for FX rates). The two sets of credentials are independent: HomeDomain + ServerSigningKey are derived from MG's published TOML and used for SEP-10 auth; ClientID + ClientSecret are issued through the MG developer portal for OAuth 2.0 client_credentials against the REST API.

MoneyGram is the platform's default cash-pickup anchor — there is no enable flag; the credentials below are always required at boot.

func (*MoneyGramConfig) AuthAddress added in v1.0.0

func (c *MoneyGramConfig) AuthAddress() (string, error)

AuthAddress returns the public G... address of the SEP-10 auth wallet.

func (*MoneyGramConfig) FundsAddress added in v1.0.0

func (c *MoneyGramConfig) FundsAddress() (string, error)

FundsAddress returns the public G... address of the funds wallet — the SEP-24 account and USDC send source.

func (*MoneyGramConfig) HasRESTCredentials added in v1.0.0

func (c *MoneyGramConfig) HasRESTCredentials() bool

HasRESTCredentials reports whether the REST API credentials are populated. Callers should fall back to YC for FX rates when this returns false.

func (*MoneyGramConfig) Validate added in v1.0.0

func (c *MoneyGramConfig) Validate() error

Validate checks that all fields required to construct a working MoneyGram client are set.

Validate intentionally does not require REST API credentials (ClientID / ClientSecret / OAuthURL / FXRateURL): the SEP-1/10/24 anchor flow can run without them, and those credentials are gated on Open Q #6 confirming MG issues REST API access to Ramps partners.

type PaymentsConfig

type PaymentsConfig struct {
	YellowCard YellowCardConfig
	Fonbnk     FonbnkConfig
	MoneyGram  MoneyGramConfig

	// EntryFXBufferPct is the flat safety margin the loan adapter applies when
	// it re-quotes the entry rate from a provider's own Quoter, as a fraction
	// (0.02 = 2 %). Nil leaves the adapter's default in place; an explicit 0
	// persists the quoted rate unbuffered. From LOAN_ENTRY_FX_BUFFER_PCT.
	//
	// Distinct from the MoneyGram orchestrator's buffers, which apply on the
	// cascade path and carry their own per-leg settings.
	EntryFXBufferPct *float64
}

PaymentsConfig bundles all payment provider configurations

type PostgresConfig

type PostgresConfig struct {
	Host     string
	User     string
	Password string
	DBName   string
	Port     string
	SSLMode  string
	TimeZone string
}

PostgresConfig holds all database-related configuration.

func (*PostgresConfig) DSN

func (c *PostgresConfig) DSN() string

DSN returns the connection string for Postgres.

type RedisConfig

type RedisConfig struct {
	Host           string
	Port           string
	Password       string
	DBNumber       int
	IdempotencyTTL time.Duration
}

RedisConfig holds all Redis-related configuration.

func (*RedisConfig) Addr

func (c *RedisConfig) Addr() string

Addr returns the host:port address for Redis.

func (*RedisConfig) GetIdempotencyTTL

func (c *RedisConfig) GetIdempotencyTTL() time.Duration

GetIdempotencyTTL returns the configured TTL or default of 24 hours

type ServerConfig

type ServerConfig struct {
	ServerEnvironment string
	ServerHost        string
	CoreServerPort    string
	CreditServerPort  string
	// PublicBaseURL is the externally-reachable origin used to build SMS
	// short-links (e.g. https://microvault.outray.app). No trailing slash.
	PublicBaseURL string
}

ServerConfig holds all server-related configuration.

func (*ServerConfig) CoreAddr

func (c *ServerConfig) CoreAddr() string

CoreAddr returns the host:port address for the core server to listen on.

func (*ServerConfig) CreditAddr

func (c *ServerConfig) CreditAddr() string

CreditAddr returns the host:port address for the credit server to listen on.

type ShortenerConfig added in v1.0.0

type ShortenerConfig struct {
	// APIKey is the dub workspace API key (from DUB_API_KEY). Presence
	// enables the shortener.
	APIKey string
	// BaseURL is the dub API origin (from DUB_API_URL), set to point at a
	// self-hosted instance. Empty uses the SDK default, https://api.dub.co.
	BaseURL string
	// Domain is the short-link domain links are created under (from
	// DUB_DOMAIN). Optional; empty lets the workspace default apply.
	Domain string
	// PreviewTitle overrides the og:title in dub Custom Link Previews (from
	// DUB_PREVIEW_TITLE). Optional; empty derives it from the destination host.
	PreviewTitle string
	// PreviewDescription overrides the og:description (from
	// DUB_PREVIEW_DESCRIPTION). Optional; empty derives it from the
	// destination host and path.
	PreviewDescription string
	// ImagePreviewURL is the og:image shown in dub Custom Link Previews
	// (from DUB_IMAGE_PREVIEW_URL). Optional.
	ImagePreviewURL string
}

ShortenerConfig configures the optional dub link shortener used for outbound cash-pickup SMS links. When APIKey is empty the shortener is off and links fall back to the self-hosted /r/{code} redirect.

func (*ShortenerConfig) Enabled added in v1.0.0

func (c *ShortenerConfig) Enabled() bool

Enabled reports whether the dub shortener should be used.

type StellarConfig

type StellarConfig struct {
	RpcURL string
	// AdminPublicKey is derived from AdminSecretKey at load, not read from the environment.
	AdminPublicKey          string
	AdminSecretKey          string
	TreasurySecretKey       string
	ServerSecretKey         string
	NetworkPassphrase       string
	EnableMultiSig          bool
	MultiSigLowThreshold    uint32
	MultiSigMediumThreshold uint32
	MultiSigHighThreshold   uint32
	USDCIssuer              string
	ContractID              string

	// AccountIndexBase advances account_index_seq at boot so a freshly rebuilt
	// (testnet) database hands out BIP44 derivation indices above any burned
	// on-chain. 0 (the default) leaves the sequence untouched. From
	// ACCOUNT_INDEX_BASE.
	AccountIndexBase int64
}

StellarConfig holds all stellar-related configuration.

func (*StellarConfig) NewRpcClient

func (c *StellarConfig) NewRpcClient() *rpcclient.Client

NewRpcClient creates a new instance of Stellar RPC Client to connect with Stellar's RPC Server

type YellowCardConfig

type YellowCardConfig struct {
	PublicKey    string
	SecretKey    string
	BaseURL      string
	BusinessID   string // Registered business ID with YellowCard
	BusinessName string // Registered business name with YellowCard
}

YellowCardConfig holds all YellowCard-related configuration

Jump to

Keyboard shortcuts

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