core

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const StatusFailure = "failure"
View Source
const StatusSuccess = "success"

Variables

View Source
var (
	ErrInvalidIDDCode       = gerror.New("invalid IDDCode")
	ErrGatewayNotFound      = gerror.New("gateway not found")
	ErrMessageTypeError     = gerror.New("message type error")
	ErrInvalidPhoneNumber   = gerror.New("invalid phone number")
	ErrRequestDataTypeError = gerror.New("request data type error")
)

Functions

This section is empty.

Types

type ClientInterface

type ClientInterface interface {
}

type ErrGatewaysFailed

type ErrGatewaysFailed struct {
	Results []*Result
}

func NewErrGatewayFailed

func NewErrGatewayFailed(results []*Result) *ErrGatewaysFailed

func (*ErrGatewaysFailed) Error

func (e *ErrGatewaysFailed) Error() string

type ErrRequestFailed

type ErrRequestFailed struct {
	StatusCode int
	Body       string
	Message    string
}

func (*ErrRequestFailed) Error

func (e *ErrRequestFailed) Error() string

type GatewayInterface

type GatewayInterface interface {

	//GetName get gateway name
	GetName() string

	// Send send message
	Send(ctx context.Context, to PhoneNumberInterface, message MessageInterface, client *gclient.Client) (string, error)
}

Gateway Interface

type Message

type Message struct {
	Content  interface{}
	Template interface{}
	Data     interface{}
	Type     interface{}
}

func (*Message) Gateways

func (m *Message) Gateways() ([]string, error)

Gateways Supported gateways.

func (*Message) GetContent

func (m *Message) GetContent(gateway GatewayInterface) (string, error)

GetContent Get message content.

func (*Message) GetData

func (m *Message) GetData(gateway GatewayInterface) (map[string]string, error)

GetData Get message data.

func (*Message) GetTemplate

func (m *Message) GetTemplate(gateway GatewayInterface) (string, error)

GetTemplate Get message template.

func (*Message) GetType

func (m *Message) GetType(gateway GatewayInterface) (string, error)

GetType Get message type.

func (*Message) Strategy

func (m *Message) Strategy() (StrategyInterface, error)

Strategy Message strategy.

type MessageInterface

type MessageInterface interface {
	// Gateways Supported gateways.
	Gateways() ([]string, error)
	// Strategy Message strategy.
	Strategy() (StrategyInterface, error)
	// GetContent Get message content.
	GetContent(gateway GatewayInterface) (string, error)
	// GetTemplate Get message template.
	GetTemplate(gateway GatewayInterface) (string, error)
	// GetData Get message data.
	GetData(gateway GatewayInterface) (map[string]string, error)
	// GetType Get message type.
	GetType(gateway GatewayInterface) (string, error)
}

MessageInterface Message interface.

type PhoneNumber

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

func NewPhoneNumber

func NewPhoneNumber(numberWithoutIDDCode int, iddCodeStr string) (*PhoneNumber, error)

func NewPhoneNumberWithoutIDDCode

func NewPhoneNumberWithoutIDDCode(numberWithoutIDDCode int) *PhoneNumber

func (*PhoneNumber) IDDCode

func (p *PhoneNumber) IDDCode() int

IDDCode e.g. 86.

func (*PhoneNumber) IsWithinChina

func (p *PhoneNumber) IsWithinChina() bool

Is within china Check if the phone number belongs to chinese mainland.

func (*PhoneNumber) Number

func (p *PhoneNumber) Number() int

Number e.g. 13800138000.

func (*PhoneNumber) PrefixedIDDCode

func (p *PhoneNumber) PrefixedIDDCode(prefix string) string

PrefixedIDDCode e.g. + -> +86

func (*PhoneNumber) String

func (p *PhoneNumber) String() string

func (*PhoneNumber) UniversalNumber

func (p *PhoneNumber) UniversalNumber() string

UniversalNumber e.g. +8613800138000.

func (*PhoneNumber) ZeroPrefixedNumber

func (p *PhoneNumber) ZeroPrefixedNumber() string

ZeroPrefixedNumber e.g. 008613800138000.

type PhoneNumberInterface

type PhoneNumberInterface interface {

	// get phone number e.g. 18800000000
	Number() int

	// get IDD code e.g. 86
	IDDCode() int

	// universal number
	UniversalNumber() string

	// add zero (e.g. 008618800000000)
	ZeroPrefixedNumber() string

	// add prefix IDD code e.g +86
	PrefixedIDDCode(prefix string) string

	// String
	String() string

	// within china
	IsWithinChina() bool
}

PhoneNumber interface

type Result

type Result struct {
	Gateway  string
	Status   string
	Template string
	Result   string
	Error    error
}

result

type StrategyInterface

type StrategyInterface interface {
	// Apply the strategy and return result.
	Apply(gateways []string) []string
}

Jump to

Keyboard shortcuts

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