Documentation
¶
Overview ¶
Package netgsm is an idiomatic Go client for the NetGSM SMS REST API (v2).
It targets https://api.netgsm.com.tr/sms/rest/v2 with HTTP Basic auth, turns NetGSM's numeric result codes into typed errors you can match with errors.Is, and is fully testable through an injectable *http.Client. The only dependency is the standard library (testify is used for tests).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMessageTooLong = &Error{kind: kindMessageTooLong, Message: "message text invalid or too long"} ErrInvalidCredentials = &Error{kind: kindInvalidCredentials, Message: "invalid credentials or no API permission"} ErrInvalidHeader = &Error{kind: kindInvalidHeader, Message: "sender header is not defined"} ErrIYSFilter = &Error{kind: kindIYSFilter, Message: "IYS-controlled sending not allowed"} ErrInvalidParams = &Error{kind: kindInvalidParams, Message: "invalid or missing parameters"} ErrDuplicateLimit = &Error{kind: kindDuplicateLimit, Message: "duplicate sending limit exceeded"} ErrSystem = &Error{kind: kindSystem, Message: "provider system error", Retryable: true} )
Sentinel errors for matching with errors.Is.
var ( ErrNoRecipients = errors.New("netgsm: no recipients") ErrEmptyMessage = errors.New("netgsm: empty message") )
ErrNoRecipients and ErrEmptyMessage are returned for invalid input before any HTTP call is made.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the NetGSM SMS REST API. It is safe for concurrent use.
type Config ¶
type Config struct {
UserCode string // NetGSM subscriber number / API sub-user
Password string // API sub-user password
Header string // default approved sender name (msgheader)
}
Config holds the NetGSM API credentials and the default approved sender.
type Error ¶
type Error struct {
Code string
Message string
Retryable bool
// contains filtered or unexported fields
}
Error is a NetGSM API error carrying the raw provider code. Match families with errors.Is (e.g. errors.Is(err, ErrInvalidHeader) covers codes 40 and 41) and inspect the concrete value with errors.As to read Code and Retryable.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithBaseURL ¶
WithBaseURL overrides the API base URL (useful for tests or a proxy).
func WithEncoding ¶
WithEncoding sets the message encoding: "TR" (default, Turkish characters) or "ASCII" (cheaper GSM-7, no Turkish characters).
func WithHTTPClient ¶
WithHTTPClient injects a custom *http.Client.
func WithTimeout ¶
WithTimeout sets the HTTP client timeout.