godapnet

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 11 Imported by: 0

README

godapnet

A Go library for sending messages to amateur radio POCSAG pagers over the DAPNET network.

go get github.com/michaelpeterswa/godapnet

Usage

package main

import (
	"context"
	"log"

	"github.com/michaelpeterswa/godapnet"
)

func main() {
	// Posts to godapnet.DAPNetURL with a 30 second timeout unless overridden
	// with godapnet.WithURL or godapnet.WithHTTPClient.
	sender := godapnet.NewSender("x1xxx", "password")

	config := godapnet.NewMessageConfig(
		[]string{"x1xxx"}, // destination callsigns
		godapnet.WithTransmitterGroups("us-wa"),
		godapnet.WithPrefix("x1xxx"), // each page reads "x1xxx: <text>"
	)

	if err := sender.Send(context.Background(), "hello from godapnet", config); err != nil {
		log.Fatal(err)
	}
}

Text longer than a page is split between words into several pages, each carrying the prefix. Pages are 80 characters (godapnet.Alphapoc602RMaxMessageLength) unless set with WithMaxMessageLength, and are sent first page first unless WithReverseOrder is given. WithEmergency marks the call as an emergency.

Send checks the config before sending anything and returns ErrNoCallsigns, ErrInvalidMaxLength, ErrPrefixTooLong or ErrEmptyText for a message it cannot send. If DAPNET rejects a page, the error wraps a *godapnet.StatusError holding the status code and the start of the response body:

var statusErr *godapnet.StatusError
if errors.As(err, &statusErr) && statusErr.StatusCode == http.StatusUnauthorized {
	// bad credentials
}

Development

make        # wire up git hooks and install commitlint
make test   # go test -race -shuffle=on ./...
make lint   # golangci-lint and yamllint, the same checks CI runs

Commits follow Conventional Commits; semantic-release cuts a GitHub release from them on every push to main.

License

MIT

Documentation

Overview

Package godapnet sends messages to amateur radio POCSAG pagers over the DAPNET network (https://hampager.de).

Index

Constants

View Source
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

View Source
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.

func NewSender added in v1.0.0

func NewSender(username string, password string, opts ...SenderOption) *Sender

NewSender returns a Sender that authenticates as username. By default it posts to DAPNetURL with an http.Client that times out after 30 seconds.

func (*Sender) Send added in v1.0.0

func (s *Sender) Send(ctx context.Context, text string, messageConfig *MessageConfig) error

Send sends text as one or more pages, as described by messageConfig. Pages are sent one at a time, so on error the returned message says how many were already delivered.

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

Jump to

Keyboard shortcuts

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