Documentation
¶
Overview ¶
Package godapnet sends messages to amateur radio POCSAG pagers over the DAPNET network (https://hampager.de).
Index ¶
Constants ¶
const ( // Alphapoc602RMaxMessageLength is the number of characters an Alphapoc // 602R pager shows per message, and the default page length. Alphapoc602RMaxMessageLength = 80 // DAPNetURL is the DAPNET calls endpoint that Sender posts to by default. DAPNetURL = "https://hampager.de/api/calls" )
Variables ¶
var ( // ErrNilConfig is returned when Send is called without a MessageConfig. ErrNilConfig = errors.New("message config is nil") // ErrNoCallsigns is returned when a MessageConfig has no destination // callsigns. ErrNoCallsigns = errors.New("no destination callsigns") // ErrInvalidMaxLength is returned when the maximum message length is not // positive. ErrInvalidMaxLength = errors.New("max message length must be positive") // ErrPrefixTooLong is returned when the prefix, plus its ": " separator, // leaves no room for text within the maximum message length. ErrPrefixTooLong = errors.New("prefix leaves no room for text") // ErrEmptyText is returned when the text to send is empty or only // whitespace. ErrEmptyText = errors.New("text is empty") )
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message struct {
Text string `json:"text"`
CallsignNames []string `json:"callSignNames"`
TransmitterGroupNames []string `json:"transmitterGroupNames"`
Emergency bool `json:"emergency"`
}
Message is the JSON body DAPNET's calls endpoint expects.
type MessageConfig ¶ added in v1.0.0
type MessageConfig struct {
// contains filtered or unexported fields
}
MessageConfig describes who receives a message and how its text is split into pages. Build one with NewMessageConfig.
func NewMessageConfig ¶ added in v1.0.0
func NewMessageConfig(callsigns []string, opts ...MessageOption) *MessageConfig
NewMessageConfig returns a config that sends to the given callsigns, with pages of at most Alphapoc602RMaxMessageLength characters unless overridden.
type MessageOption ¶ added in v1.0.0
type MessageOption func(*MessageConfig)
MessageOption configures a MessageConfig.
func WithEmergency ¶ added in v1.0.0
func WithEmergency() MessageOption
WithEmergency marks the message as an emergency call.
func WithMaxMessageLength ¶ added in v1.0.0
func WithMaxMessageLength(n int) MessageOption
WithMaxMessageLength sets the maximum number of characters in each page.
func WithPrefix ¶ added in v1.0.0
func WithPrefix(prefix string) MessageOption
WithPrefix starts every page with "<prefix>: ", typically the sender's callsign. The prefix counts towards the maximum message length.
func WithReverseOrder ¶ added in v1.0.0
func WithReverseOrder() MessageOption
WithReverseOrder sends the pages of a long message last page first, for pagers that list the most recent message at the top.
func WithTransmitterGroups ¶ added in v1.0.0
func WithTransmitterGroups(groups ...string) MessageOption
WithTransmitterGroups sets the transmitter groups that broadcast the message.
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender sends calls to DAPNET with one account's credentials.
type SenderOption ¶ added in v1.0.0
type SenderOption func(*Sender)
SenderOption configures a Sender.
func WithHTTPClient ¶ added in v1.0.0
func WithHTTPClient(client *http.Client) SenderOption
WithHTTPClient sends requests with client instead of the default.
func WithURL ¶ added in v1.0.0
func WithURL(url string) SenderOption
WithURL posts calls to url instead of DAPNetURL.
type StatusError ¶ added in v1.0.0
type StatusError struct {
StatusCode int
Status string
// Body is the start of DAPNET's response body, trimmed of whitespace.
Body string
}
StatusError is returned when DAPNET answers a call with anything other than 201 Created. Use errors.As to inspect it, for example to detect rejected credentials with StatusCode == http.StatusUnauthorized.
func (*StatusError) Error ¶ added in v1.0.0
func (e *StatusError) Error() string