dxcc

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 19 Imported by: 0

Documentation ยถ

Index ยถ

Constants ยถ

View Source
const (
	DBFileName = "dxcc.db" // Made public for use in main and tests

)

Variables ยถ

View Source
var FlagEmojis = map[string]string{

	"1":   "๐Ÿ‡จ๐Ÿ‡ฆ",
	"291": "๐Ÿ‡บ๐Ÿ‡ธ",
	"50":  "๐Ÿ‡ฒ๐Ÿ‡ฝ",
	"70":  "๐Ÿ‡จ๐Ÿ‡บ",
	"105": "๐Ÿ‡บ๐Ÿ‡ธ",

	"100": "๐Ÿ‡ฆ๐Ÿ‡ท",
	"108": "๐Ÿ‡ง๐Ÿ‡ท",
	"144": "๐Ÿ‡บ๐Ÿ‡พ",
	"112": "๐Ÿ‡จ๐Ÿ‡ฑ",
	"116": "๐Ÿ‡จ๐Ÿ‡ด",
	"136": "๐Ÿ‡ต๐Ÿ‡ช",
	"140": "๐Ÿ‡ป๐Ÿ‡ช",
	"120": "๐Ÿ‡ช๐Ÿ‡จ",
	"124": "๐Ÿ‡ฌ๐Ÿ‡พ",
	"132": "๐Ÿ‡ต๐Ÿ‡พ",
	"129": "๐Ÿ‡ฌ๐Ÿ‡ซ",

	"10":  "๐Ÿ‡ณ๐Ÿ‡ฑ",
	"14":  "๐Ÿ‡ฆ๐Ÿ‡น",
	"15":  "๐Ÿ‡ง๐Ÿ‡ช",
	"503": "๐Ÿ‡จ๐Ÿ‡ฟ",
	"160": "๐Ÿ‡ฉ๐Ÿ‡ฐ",
	"224": "๐Ÿ‡ซ๐Ÿ‡ฎ",
	"227": "๐Ÿ‡ซ๐Ÿ‡ท",
	"230": "๐Ÿ‡ฉ๐Ÿ‡ช",
	"236": "๐Ÿ‡ฌ๐Ÿ‡ท",
	"239": "๐Ÿ‡ญ๐Ÿ‡บ",
	"251": "๐Ÿ‡ฎ๐Ÿ‡ธ",
	"245": "๐Ÿ‡ฎ๐Ÿ‡ช",
	"248": "๐Ÿ‡ฎ๐Ÿ‡น",
	"260": "๐Ÿ‡ฒ๐Ÿ‡จ",
	"266": "๐Ÿ‡ณ๐Ÿ‡ด",
	"269": "๐Ÿ‡ต๐Ÿ‡ฑ",
	"272": "๐Ÿ‡ต๐Ÿ‡น",
	"54":  "๐Ÿ‡ท๐Ÿ‡บ",
	"281": "๐Ÿ‡ช๐Ÿ‡ธ",
	"284": "๐Ÿ‡ธ๐Ÿ‡ช",
	"287": "๐Ÿ‡จ๐Ÿ‡ญ",
	"288": "๐Ÿ‡บ๐Ÿ‡ฆ",
	"223": "๐Ÿ‡ฌ๐Ÿ‡ง",
	"212": "๐Ÿ‡ง๐Ÿ‡ฌ",
	"275": "๐Ÿ‡ท๐Ÿ‡ด",

	"339": "๐Ÿ‡ฏ๐Ÿ‡ต",
	"318": "๐Ÿ‡จ๐Ÿ‡ณ",
	"137": "๐Ÿ‡ฐ๐Ÿ‡ท",
	"324": "๐Ÿ‡ฎ๐Ÿ‡ณ",
	"387": "๐Ÿ‡น๐Ÿ‡ญ",
	"293": "๐Ÿ‡ป๐Ÿ‡ณ",
	"327": "๐Ÿ‡ฎ๐Ÿ‡ฉ",
	"375": "๐Ÿ‡ต๐Ÿ‡ญ",
	"381": "๐Ÿ‡ธ๐Ÿ‡ฌ",
	"333": "๐Ÿ‡ฒ๐Ÿ‡พ",
	"390": "๐Ÿ‡น๐Ÿ‡ผ",
	"321": "๐Ÿ‡ญ๐Ÿ‡ฐ",

	"150": "๐Ÿ‡ฆ๐Ÿ‡บ",
	"170": "๐Ÿ‡ณ๐Ÿ‡ฟ",
	"176": "๐Ÿ‡ซ๐Ÿ‡ฏ",
	"163": "๐Ÿ‡ต๐Ÿ‡ฌ",
	"158": "๐Ÿ‡ป๐Ÿ‡บ",
	"162": "๐Ÿ‡ณ๐Ÿ‡จ",
	"175": "๐Ÿ‡ต๐Ÿ‡ซ",

	"462": "๐Ÿ‡ฟ๐Ÿ‡ฆ",
	"478": "๐Ÿ‡ช๐Ÿ‡ฌ",
	"430": "๐Ÿ‡ฐ๐Ÿ‡ช",
	"450": "๐Ÿ‡ณ๐Ÿ‡ฌ",
	"446": "๐Ÿ‡ฒ๐Ÿ‡ฆ",
	"474": "๐Ÿ‡น๐Ÿ‡ณ",
	"438": "๐Ÿ‡ฒ๐Ÿ‡ฌ",
	"453": "๐Ÿ‡ท๐Ÿ‡ช",
	"165": "๐Ÿ‡ฒ๐Ÿ‡บ",

	"13":  "๐Ÿ‡ฆ๐Ÿ‡ถ",
	"460": "",
	"901": "",
}

FlagEmojis is a comprehensive mapping of DXCC ID (as string) to emoji flag. This covers the most common amateur radio countries and entities.

Functions ยถ

func ToUcWord ยถ

func ToUcWord(s string) string

ToUcWord is an exported wrapper for toUcWord used by tests.

Types ยถ

type Client ยถ

type Client struct {

	// Expose for testing
	PrefixesMap   map[string]DxccPrefix
	ExceptionsMap map[string]DxccException
	EntitiesMap   map[int]DxccEntity
	// Testing hook to override http client behavior
	HTTPClient HTTPDoer
	// TestFallback when true enables a small, test-only fallback mapping for missing entities.
	TestFallback bool
	// contains filtered or unexported fields
}

Client manages DXCC data.

func NewClient ยถ

func NewClient(ctx context.Context, cfg config.Config, dbClient db.DBClient) (*Client, error)

NewClient creates and returns a new DXCC client.

func (*Client) Close ยถ

func (c *Client) Close() error

Close gracefully shuts down the DXCC client's resources.

func (*Client) FetchAndStore ยถ

func (c *Client) FetchAndStore(ctx context.Context)

FetchAndStore exposes the internal fetchAndStoreData for tests.

func (*Client) FetchAndStoreData ยถ

func (c *Client) FetchAndStoreData(ctx context.Context)

func (*Client) GetDxccInfo ยถ

func (c *Client) GetDxccInfo(ctx context.Context, callsign string, lookupDate *time.Time) (*DxccInfo, error)

GetDxccInfo performs a DXCC lookup for a given callsign. It also takes an optional 'lookupDate' for historical lookups, though current implementation mainly relies on current loaded data.

func (*Client) GetEntities ยถ

func (c *Client) GetEntities() map[int]DxccEntity

GetEntities exposes the internal entities map for tests.

func (*Client) GetException ยถ

func (c *Client) GetException(call string) (*DxccInfo, bool)

GetException checks if a callsign has a hardcoded exception entry. Returns (entity, found).

func (*Client) GetExceptions ยถ

func (c *Client) GetExceptions() map[string]DxccException

GetExceptions exposes the internal exceptions map for tests.

func (*Client) GetHTTPClient ยถ

func (c *Client) GetHTTPClient() *http.Client

GetHTTPClient exposes the internal http client for tests.

func (*Client) GetLastDownloadTime ยถ

func (c *Client) GetLastDownloadTime(ctx context.Context) (time.Time, error)

GetLastDownloadTime retrieves when DXCC data was last downloaded.

func (*Client) GetPrefix ยถ

func (c *Client) GetPrefix(prefix string) (*DxccInfo, bool)

GetPrefix looks up a prefix in the DXCC prefix map. Returns (entity, found).

func (*Client) GetPrefixes ยถ

func (c *Client) GetPrefixes() map[string]DxccPrefix

GetPrefixes exposes the internal prefixes map for tests.

func (*Client) LoadMaps ยถ

func (c *Client) LoadMaps(ctx context.Context) error

LoadMaps exposes the internal loadMapsFromDB functionality for tests.

func (*Client) LoadMapsFromDB ยถ

func (c *Client) LoadMapsFromDB(ctx context.Context) error

Compatibility aliases for tests: previous tests expect these names.

func (*Client) SetHTTPDoer ยถ

func (c *Client) SetHTTPDoer(d HTTPDoer)

SetHTTPDoer allows tests to inject a custom HTTP client that satisfies HTTPDoer.

func (*Client) StartUpdater ยถ

func (c *Client) StartUpdater(ctx context.Context)

StartUpdater starts the periodic update job for DXCC data. Note: Does NOT perform an initial check - main.go handles that synchronously before calling this.

type ClubLogXML ยถ

type ClubLogXML struct {
	XMLName    xml.Name   `xml:"clublog"`
	Date       string     `xml:"date,attr"`
	Prefixes   Prefixes   `xml:"prefixes"`
	Exceptions Exceptions `xml:"exceptions"`
	Entities   Entities   `xml:"entities"`
}

ClubLogXML represents the root of the new Club Log XML format.

type CtyXML ยถ

type CtyXML struct {
	XMLName    xml.Name   `xml:"cty"`
	Prefixes   Prefixes   `xml:"prefixes"`
	Exceptions Exceptions `xml:"exceptions"`
	Entities   Entities   `xml:"entities"`
}

CtyXML represents the root of the legacy cty.xml file.

type DxccEntity ยถ

type DxccEntity struct {
	ADIF   int       `json:"adif"`
	Name   string    `json:"name"`
	Prefix string    `json:"prefix"`
	ITUZ   int       `json:"ituz"`
	CQZ    int       `json:"cqz"`
	Cont   string    `json:"cont"`
	Long   float64   `json:"long"`
	Lat    float64   `json:"lat"`
	Start  time.Time `json:"start"`
	End    time.Time `json:"end"`
}

DxccEntity represents a row in the dxcc_entities table.

type DxccException ยถ

type DxccException DxccPrefix // Same structure as DxccPrefix for simplicity

DxccException represents a row in the dxcc_exceptions table.

type DxccInfo ยถ

type DxccInfo struct {
	Cont      string  `json:"cont"`
	Entity    string  `json:"entity"`
	Flag      string  `json:"flag"` // Emoji flag
	DXCCID    int     `json:"dxcc_id"`
	CQZ       int     `json:"cqz"`
	ITUZ      int     `json:"ituz"`
	Latitude  float64 `json:"lat"`
	Longitude float64 `json:"lng"`
}

DxccInfo holds comprehensive DXCC information for a callsign. This is the output format from the lookup.

type DxccPrefix ยถ

type DxccPrefix struct {
	Call   string    `json:"call"`
	Entity string    `json:"entity"`
	ADIF   int       `json:"adif"`
	CQZ    int       `json:"cqz"`
	Cont   string    `json:"cont"`
	Long   float64   `json:"long"`
	Lat    float64   `json:"lat"`
	Start  time.Time `json:"start"` // Stored as TEXT (ISO 8601) in DB
	End    time.Time `json:"end"`   // Stored as TEXT (ISO 8601) in DB
}

DxccPrefix represents a row in the dxcc_prefixes table.

type Entities ยถ

type Entities struct {
	XMLName xml.Name `xml:"entities"`
	Entity  []Entity `xml:"entity"`
}

Entities holds a list of Entity records.

type Entity ยถ

type Entity struct {
	XMLName xml.Name `xml:"entity"`
	ADIF    int      `xml:"adif,attr"`
	Name    string   `xml:"name"`   // Often the same as 'entity' in prefix, but can differ.
	Prefix  string   `xml:"prefix"` // Primary prefix for the entity
	ITUZ    int      `xml:"ituz"`   // ITU Zone is here
	CQZ     int      `xml:"cqz"`
	Cont    string   `xml:"cont"`
	Long    float64  `xml:"long"`
	Lat     float64  `xml:"lat"`
	Start   string   `xml:"start"`
	End     string   `xml:"end"`
}

Entity represents a single DXCC entity entry (for global entity data like ITU zone).

type Exception ยถ

type Exception struct {
	XMLName  xml.Name `xml:"exception"`
	RecordID int      `xml:"record,attr"`
	Call     string   `xml:"call"`
	Entity   string   `xml:"entity"`
	ADIF     int      `xml:"adif"`
	CQZ      int      `xml:"cqz"`
	Cont     string   `xml:"cont"`
	Long     float64  `xml:"long"`
	Lat      float64  `xml:"lat"`
	Start    string   `xml:"start"`
	End      string   `xml:"end"`
}

Exception represents a single DXCC exception entry.

type Exceptions ยถ

type Exceptions struct {
	XMLName   xml.Name    `xml:"exceptions"`
	Exception []Exception `xml:"exception"`
}

Exceptions holds a list of Exception records.

type HTTPDoer ยถ

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer is a minimal interface for http clients used in tests.

type Prefix ยถ

type Prefix struct {
	XMLName  xml.Name `xml:"prefix"`
	RecordID int      `xml:"record,attr"` // 'record' attribute
	Call     string   `xml:"call"`
	Entity   string   `xml:"entity"`
	ADIF     int      `xml:"adif"`
	CQZ      int      `xml:"cqz"`
	Cont     string   `xml:"cont"`
	Long     float64  `xml:"long"`
	Lat      float64  `xml:"lat"`
	Start    string   `xml:"start"` // Will parse to time.Time
	End      string   `xml:"end"`   // Will parse to time.Time
}

Prefix represents a single DXCC prefix entry.

type Prefixes ยถ

type Prefixes struct {
	XMLName xml.Name `xml:"prefixes"`
	Prefix  []Prefix `xml:"prefix"`
}

Prefixes holds a list of Prefix records.

Jump to

Keyboard shortcuts

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