sms

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDriverRequired = errors.New("sms: driver is required")
	ErrUnknownDriver  = errors.New("sms: unknown driver")
)

Functions

func RegisterDriver

func RegisterDriver(driver string, factory DriverFactory)

Types

type AttemptResult

type AttemptResult struct {
	Provider string
	Success  bool
	Result   *ProviderResult
	Error    error
}

type DriverFactory

type DriverFactory func(name string, cfg ProviderConfig) (Provider, error)

type Message

type Message interface {
	Resolve(ctx context.Context, provider ProviderConfig) (Payload, error)
}

type Middleware

type Middleware func(Sender) Sender

type Param

type Param struct {
	Key   string
	Value any
}

type Payload

type Payload struct {
	Content  string
	Template string
	Data     []Param
}

func (Payload) DataMap

func (p Payload) DataMap() map[string]any

func (Payload) DataValues

func (p Payload) DataValues() []any

type Provider

type Provider interface {
	Send(ctx context.Context, req ProviderRequest) (*ProviderResult, error)
	Close() error
}

func NewProvider

func NewProvider(name string, cfg ProviderConfig) (Provider, error)

type ProviderConfig

type ProviderConfig struct {
	Driver          string        `mapstructure:"driver" yaml:"driver"`
	Account         string        `mapstructure:"account" yaml:"account"`
	Password        string        `mapstructure:"password" yaml:"password"`
	AppKey          string        `mapstructure:"app_key" yaml:"app_key"`
	AppSecret       string        `mapstructure:"app_secret" yaml:"app_secret"`
	AccessKeyID     string        `mapstructure:"access_key_id" yaml:"access_key_id"`
	AccessKeySecret string        `mapstructure:"access_key_secret" yaml:"access_key_secret"`
	RegionID        string        `mapstructure:"region_id" yaml:"region_id"`
	SignID          string        `mapstructure:"sign_id" yaml:"sign_id"`
	SignName        string        `mapstructure:"sign_name" yaml:"sign_name"`
	Endpoint        string        `mapstructure:"endpoint" yaml:"endpoint"`
	Timeout         time.Duration `mapstructure:"timeout" yaml:"timeout"`

	Name string `mapstructure:"-" yaml:"-"`
}

func (ProviderConfig) AccessKey

func (c ProviderConfig) AccessKey() string

func (ProviderConfig) Clone

func (c ProviderConfig) Clone() ProviderConfig

func (ProviderConfig) Region

func (c ProviderConfig) Region() string

func (ProviderConfig) SecretKey

func (c ProviderConfig) SecretKey() string

type ProviderMessage

type ProviderMessage interface {
	Message
	Providers(ctx context.Context) []string
}

type ProviderRequest

type ProviderRequest struct {
	To       []string
	Message  Message
	Payload  Payload
	Provider ProviderConfig
}

type ProviderResult

type ProviderResult struct {
	Provider  string
	Success   bool
	Code      string
	Message   string
	MessageNo string
	Raw       any
}

type Request

type Request struct {
	To        []string
	Message   Message
	Providers []string
}

type SendResult

type SendResult struct {
	Provider string
	Attempts []AttemptResult
}

type Sender

type Sender interface {
	Send(ctx context.Context, req Request) (*SendResult, error)
}

type SenderFunc

type SenderFunc func(ctx context.Context, req Request) (*SendResult, error)

func (SenderFunc) Send

func (fn SenderFunc) Send(ctx context.Context, req Request) (*SendResult, error)

type TemplateMessage

type TemplateMessage struct {
	Content       string
	Template      string
	Data          []Param
	ProviderNames []string
}

func (TemplateMessage) Providers

func (m TemplateMessage) Providers(context.Context) []string

func (TemplateMessage) Resolve

Directories

Path Synopsis
driver

Jump to

Keyboard shortcuts

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