config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package config provides configuration loading and management for message providers.

The configuration system supports multiple message provider types (Email, SMS, Push, Chat) and automatically discovers provider configurations from environment variables with the MESSAGE_ prefix.

Environment Variable Format

Provider configurations are auto-discovered from environment variables:

MESSAGE_<PROVIDER>_API_KEY=...
MESSAGE_<PROVIDER>_API_SECRET=...
MESSAGE_<PROVIDER>_REGION=...
MESSAGE_<PROVIDER>_BASE_URL=...

Type-specific fields are also loaded:

Email: MESSAGE_<PROVIDER>_DOMAIN, MESSAGE_<PROVIDER>_FROM_EMAIL, MESSAGE_<PROVIDER>_FROM_NAME
SMS:   MESSAGE_<PROVIDER>_FROM_PHONE
Push:  MESSAGE_<PROVIDER>_APP_ID, MESSAGE_<PROVIDER>_TOPIC
Chat:  MESSAGE_<PROVIDER>_FROM_PHONE, MESSAGE_<PROVIDER>_WEBHOOK_URL

Usage

cfg, err := config.LoadFromEnv()
if err != nil {
    log.Fatal(err)
}

// Access email providers
mailgun := cfg.EmailProviders["mailgun"]

Extending with Custom Providers

Register custom providers before calling LoadFromEnv:

config.RegisterProvider("myservice", config.ProviderTypeEmail)
cfg, _ := config.LoadFromEnv() // Now recognizes MESSAGE_MYSERVICE_* vars

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterProvider

func RegisterProvider(name string, pType ProviderType)

RegisterProvider registers a new provider type for auto-discovery. This function is safe for concurrent use.

Types

type ChatConfig

type ChatConfig struct {
	CommonConfig
	FromPhone  string
	WebhookURL string // e.g. Slack/Teams Webhook
}

ChatConfig specific configuration for Chat providers

type CommonConfig

type CommonConfig struct {
	APIKey    string
	APISecret string
	Region    string
	BaseURL   string
	Extra     map[string]string
}

CommonConfig shared fields across all providers

type Config

type Config struct {
	DefaultEmailProvider string
	DefaultSMSProvider   string
	DefaultPushProvider  string
	DefaultChatProvider  string

	// Typed provider configurations
	EmailProviders map[string]EmailConfig
	SMSProviders   map[string]SMSConfig
	PushProviders  map[string]PushConfig
	ChatProviders  map[string]ChatConfig
}

Config holds all provider configurations

func LoadFromEnv

func LoadFromEnv() (*Config, error)

LoadFromEnv loads configuration from environment variables

func NewConfig

func NewConfig() *Config

NewConfig creates a new empty Config

type EmailConfig

type EmailConfig struct {
	CommonConfig
	Domain    string
	FromEmail string
	FromName  string
}

EmailConfig specific configuration for Email providers

type ProviderType

type ProviderType string

ProviderType defines the type of message provider

const (
	ProviderTypeEmail ProviderType = "email"
	ProviderTypeSMS   ProviderType = "sms"
	ProviderTypePush  ProviderType = "push"
	ProviderTypeChat  ProviderType = "chat"
)

type PushConfig

type PushConfig struct {
	CommonConfig
	AppID string // e.g. OneSignal App ID
	Topic string // e.g. APNS Topic / Bundle ID
}

PushConfig specific configuration for Push providers

type SMSConfig

type SMSConfig struct {
	CommonConfig
	FromPhone string
}

SMSConfig specific configuration for SMS providers

Jump to

Keyboard shortcuts

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