Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 30, 2025

The flag field was missing from JSON output when DXCC lookups used GetPrefix() or GetException() code paths, while other paths like buildDxccInfoFromPrefix() correctly populated it. This inconsistency stemmed from four different functions building DxccInfo objects independently.

Changes

Created single source of truth for DXCC output formatting:

  • Added utils.BuildDxccInfo() - public function that constructs complete DxccInfo with flag lookup via FlagEmojis[adif]
  • Added backend/dxcc.buildDxccInfo() - internal helper with applyTitleCase parameter for flexibility
  • Added utils.toUcWord() - title case helper for consistent entity name formatting

Updated all four builders to use centralized function:

  • GetPrefix() - now calls buildDxccInfo() with flag population
  • GetException() - now calls buildDxccInfo() with flag population
  • buildDxccInfoFromPrefix() - refactored to use buildDxccInfo()
  • buildDxccInfoFromEntity() - refactored to use buildDxccInfo()

Before:

func (c *Client) GetPrefix(prefix string) (*DxccInfo, bool) {
    // ...
    info := &DxccInfo{
        DXCCID: pfx.ADIF,
        Entity: pfx.Entity,
        CQZ:    pfx.CQZ,
        Cont:   pfx.Cont,
        // No Flag, ITUZ, Lat, Lng
    }
    return info, true
}

After:

func (c *Client) GetPrefix(prefix string) (*DxccInfo, bool) {
    // ...
    info := buildDxccInfo(pfx.ADIF, pfx.Cont, pfx.Entity, pfx.CQZ, ituz, pfx.Lat, pfx.Long, false)
    return info, true  // Flag now populated: FlagEmojis[adif]
}

All four code paths now consistently return complete DxccInfo objects with flags.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.clublog.org
    • Triggering command: /tmp/go-build2074946279/b001/utils.test /tmp/go-build2074946279/b001/utils.test -test.testlogfile=/tmp/go-build2074946279/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a (dns block)
    • Triggering command: /tmp/go-build3717207601/b001/utils.test /tmp/go-build3717207601/b001/utils.test -test.testlogfile=/tmp/go-build3717207601/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true cgo (dns block)
    • Triggering command: /tmp/go-build2621242724/b407/utils.test /tmp/go-build2621242724/b407/utils.test -test.testlogfile=/tmp/go-build2621242724/b407/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true x64/src/runtime/cgo CzK_-vitg ux_amd64/compile (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Problem

Issue #21 reports that the "flag" field is missing from the JSON output even though other DXCC data (entity, continent, DXCC ID) are present. This is caused by multiple functions building DxccInfo objects inconsistently - some set the flag field while others don't.

Current Issue

There are currently 4 functions that build/return DxccInfo objects:

  • buildDxccInfoFromPrefix() - Sets flag ✅
  • buildDxccInfoFromEntity() - Sets flag ✅
  • GetPrefix() - Does NOT set flag ❌
  • GetException() - Does NOT set flag ❌

This duplication makes it difficult to maintain consistent DXCC output and causes the flag to be missing when certain code paths are used (e.g., LookupDXCC() utility function uses only GetPrefix() and GetException()).

Solution

Create a single, centralized function in utils/dxcc_lookup.go that builds complete DxccInfo objects with all fields populated including the flag. This function will:

  1. Take basic DXCC data as parameters (ADIF, continent, entity, CQZ, ITUZ, latitude, longitude)
  2. Look up the flag emoji from the FlagEmojis map based on ADIF
  3. Apply title case to entity names for consistency
  4. Return a complete, properly formatted DxccInfo object

All builders in backend/dxcc/client.go will be updated to call this single utility function, eliminating duplication and ensuring consistency across all code paths.

Benefits

  • Single source of truth for DXCC output formatting
  • Fixes missing flags in all scenarios
  • Makes future DXCC output adjustments easier (only one place to modify)
  • Better separation of concerns (retrieval in backend, formatting in utils)
  • Ensures flag field is always populated when ADIF data is available

Files to Modify

  1. utils/dxcc_lookup.go - Add new BuildDxccInfo() function and helper toUcWord() for consistency
  2. backend/dxcc/client.go - Update buildDxccInfoFromPrefix(), buildDxccInfoFromEntity(), GetPrefix(), and GetException() to use the new utility function

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Added BuildDxccInfo() function in utils/dxcc_lookup.go as single source of truth
- Added toUcWord() helper in utils for title case conversion
- Created internal buildDxccInfo() in backend/dxcc/client.go with applyTitleCase parameter
- Updated GetPrefix() and GetException() to use buildDxccInfo() with flag population
- Updated buildDxccInfoFromPrefix() and buildDxccInfoFromEntity() to use buildDxccInfo()
- Added comprehensive tests to verify flag field is populated in all scenarios
- All existing tests pass without regressions

Co-authored-by: user00265 <8064+user00265@users.noreply.github.com>
Copilot AI changed the title [WIP] Create centralized function for DxccInfo object creation Centralize DXCC info building to fix missing flag field Dec 30, 2025
Copilot AI requested a review from user00265 December 30, 2025 15:57
 - Correct `lotw_user` output to display days since last update instead of hard-coded "2"
 - Added `ituz` to output to go alongside `cqz`
 - Added `mode`, `submode`, and `band` to cluster spots (for unified format)
 - Added `mode` and `submode` to POTA spots (for unified format)

This should compliment the `flag` output and start some refactoring of repeated functions
@user00265 user00265 changed the title Centralize DXCC info building to fix missing flag field Fix missing fields and unset fields Dec 30, 2025
@user00265
Copy link
Owner

Making this a partial refactor and correction of other fields found that were not outputting or included at all from the original after looking at the code from my dev computer. This should work.

WIP.

@user00265 user00265 marked this pull request as ready for review January 2, 2026 15:15
@user00265
Copy link
Owner

This corrects and closes issue #21

@user00265 user00265 closed this Jan 2, 2026
@user00265 user00265 reopened this Jan 2, 2026
Copy link
Owner

@user00265 user00265 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go.

@user00265 user00265 merged commit 4e87ef0 into master Jan 2, 2026
4 of 5 checks passed
@user00265 user00265 deleted the copilot/centralize-dxccinfo-builder branch January 2, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants