style: Apply code formatting with go fmt

- Run 'make format' to ensure all Go code follows standard formatting
- Maintains consistent code style across the entire codebase
- No functional changes, only whitespace and formatting improvements
This commit is contained in:
Ole-Morten Duesund 2025-09-01 10:05:29 +02:00
commit 2bffa2c418
19 changed files with 543 additions and 527 deletions

View file

@ -72,10 +72,10 @@ func NewDatabase() *Database {
db := &Database{
codes: make(map[string]*CodeInfo),
}
// Initialize with standard transponder codes
db.loadStandardCodes()
return db
}
@ -107,7 +107,7 @@ func (db *Database) loadStandardCodes() {
Priority: 90,
Notes: "General emergency situation requiring immediate attention",
},
// Standard VFR/IFR Codes
{
Code: "1200",
@ -149,7 +149,7 @@ func (db *Database) loadStandardCodes() {
Priority: 5,
Notes: "Transponder operating but no specific code assigned",
},
// Special Purpose Codes
{
Code: "1255",
@ -175,7 +175,7 @@ func (db *Database) loadStandardCodes() {
Priority: 35,
Notes: "Military interceptor aircraft",
},
// Military Ranges
{
Code: "4000",
@ -193,7 +193,7 @@ func (db *Database) loadStandardCodes() {
Priority: 12,
Notes: "Military interceptor operations (0100-0777 range)",
},
// Additional Common Codes
{
Code: "1201",
@ -219,7 +219,7 @@ func (db *Database) loadStandardCodes() {
Priority: 8,
Notes: "VFR flight above 12,500 feet requiring transponder",
},
// European Specific
{
Code: "7001",
@ -246,7 +246,7 @@ func (db *Database) loadStandardCodes() {
Notes: "General Air Traffic operating in Other Air Traffic area",
},
}
// Add all codes to the database
for _, code := range codes {
db.codes[code.Code] = code
@ -254,7 +254,7 @@ func (db *Database) loadStandardCodes() {
}
// Lookup returns information about a given transponder code
//
//
// The method accepts both 4-digit strings and integers, automatically
// formatting them as needed. Returns nil if the code is not found in the database.
//
@ -308,13 +308,13 @@ func (db *Database) LookupHex(hexCode string) *CodeInfo {
// - []*CodeInfo: Slice of all emergency codes, sorted by priority (highest first)
func (db *Database) GetEmergencyCodes() []*CodeInfo {
var emergencyCodes []*CodeInfo
for _, info := range db.codes {
if info.Type == Emergency {
emergencyCodes = append(emergencyCodes, info)
}
}
// Sort by priority (highest first)
for i := 0; i < len(emergencyCodes); i++ {
for j := i + 1; j < len(emergencyCodes); j++ {
@ -323,7 +323,7 @@ func (db *Database) GetEmergencyCodes() []*CodeInfo {
}
}
}
return emergencyCodes
}
@ -379,7 +379,7 @@ func (db *Database) FormatSquawkWithDescription(code string) string {
if info == nil {
return code // Return just the code if no description available
}
switch info.Type {
case Emergency:
return fmt.Sprintf("%s (⚠️ EMERGENCY - %s)", code, info.Description)
@ -390,4 +390,4 @@ func (db *Database) FormatSquawkWithDescription(code string) string {
default:
return fmt.Sprintf("%s (%s)", code, info.Description)
}
}
}

View file

@ -9,7 +9,7 @@ func TestNewDatabase(t *testing.T) {
if db == nil {
t.Fatal("NewDatabase() returned nil")
}
if len(db.codes) == 0 {
t.Error("Database should contain pre-loaded codes")
}
@ -17,20 +17,20 @@ func TestNewDatabase(t *testing.T) {
func TestEmergencyCodes(t *testing.T) {
db := NewDatabase()
emergencyCodes := []string{"7500", "7600", "7700"}
for _, code := range emergencyCodes {
info := db.Lookup(code)
if info == nil {
t.Errorf("Emergency code %s not found", code)
continue
}
if info.Type != Emergency {
t.Errorf("Code %s should be Emergency type, got %s", code, info.Type)
}
if !db.IsEmergencyCode(code) {
t.Errorf("IsEmergencyCode(%s) should return true", code)
}
@ -39,7 +39,7 @@ func TestEmergencyCodes(t *testing.T) {
func TestStandardCodes(t *testing.T) {
db := NewDatabase()
testCases := []struct {
code string
description string
@ -48,16 +48,16 @@ func TestStandardCodes(t *testing.T) {
{"7000", "VFR - Visual Flight Rules"},
{"1000", "Mode A/C Not Assigned"},
}
for _, tc := range testCases {
info := db.Lookup(tc.code)
if info == nil {
t.Errorf("Standard code %s not found", tc.code)
continue
}
if info.Description != tc.description {
t.Errorf("Code %s: expected description %q, got %q",
t.Errorf("Code %s: expected description %q, got %q",
tc.code, tc.description, info.Description)
}
}
@ -65,17 +65,17 @@ func TestStandardCodes(t *testing.T) {
func TestLookupInt(t *testing.T) {
db := NewDatabase()
// Test integer lookup
info := db.LookupInt(7700)
if info == nil {
t.Fatal("LookupInt(7700) returned nil")
}
if info.Code != "7700" {
t.Errorf("Expected code '7700', got '%s'", info.Code)
}
if info.Type != Emergency {
t.Errorf("Code 7700 should be Emergency type, got %s", info.Type)
}
@ -83,11 +83,11 @@ func TestLookupInt(t *testing.T) {
func TestLookupHex(t *testing.T) {
db := NewDatabase()
// 7700 in octal is 3840 in decimal, which is F00 in hex
// However, squawk codes are transmitted differently in different formats
// For now, test with a simple hex conversion
// Test invalid hex
info := db.LookupHex("INVALID")
if info != nil {
@ -97,7 +97,7 @@ func TestLookupHex(t *testing.T) {
func TestFormatSquawkWithDescription(t *testing.T) {
db := NewDatabase()
testCases := []struct {
code string
expected string
@ -108,7 +108,7 @@ func TestFormatSquawkWithDescription(t *testing.T) {
{"0000", "0000 (🔰 No Transponder/Military)"},
{"9999", "9999"}, // Unknown code should return just the code
}
for _, tc := range testCases {
result := db.FormatSquawkWithDescription(tc.code)
if result != tc.expected {
@ -120,12 +120,12 @@ func TestFormatSquawkWithDescription(t *testing.T) {
func TestGetEmergencyCodes(t *testing.T) {
db := NewDatabase()
emergencyCodes := db.GetEmergencyCodes()
if len(emergencyCodes) != 3 {
t.Errorf("Expected 3 emergency codes, got %d", len(emergencyCodes))
}
// Check that they're sorted by priority (highest first)
for i := 1; i < len(emergencyCodes); i++ {
if emergencyCodes[i-1].Priority < emergencyCodes[i].Priority {
@ -136,7 +136,7 @@ func TestGetEmergencyCodes(t *testing.T) {
func TestAddCustomCode(t *testing.T) {
db := NewDatabase()
customCode := &CodeInfo{
Code: "1234",
Description: "Test Custom Code",
@ -145,14 +145,14 @@ func TestAddCustomCode(t *testing.T) {
Priority: 50,
Notes: "This is a test custom code",
}
db.AddCustomCode(customCode)
info := db.Lookup("1234")
if info == nil {
t.Fatal("Custom code not found after adding")
}
if info.Description != "Test Custom Code" {
t.Errorf("Custom code description mismatch: expected %q, got %q",
"Test Custom Code", info.Description)
@ -170,7 +170,7 @@ func TestCodeTypeString(t *testing.T) {
{Military, "Military"},
{Special, "Special"},
}
for _, tc := range testCases {
result := tc.codeType.String()
if result != tc.expected {
@ -181,16 +181,16 @@ func TestCodeTypeString(t *testing.T) {
func TestGetAllCodes(t *testing.T) {
db := NewDatabase()
allCodes := db.GetAllCodes()
if len(allCodes) == 0 {
t.Error("GetAllCodes() should return non-empty slice")
}
// Verify we can find known codes in the result
found7700 := false
found1200 := false
for _, code := range allCodes {
if code.Code == "7700" {
found7700 = true
@ -199,11 +199,11 @@ func TestGetAllCodes(t *testing.T) {
found1200 = true
}
}
if !found7700 {
t.Error("Emergency code 7700 not found in GetAllCodes() result")
}
if !found1200 {
t.Error("Standard code 1200 not found in GetAllCodes() result")
}
}
}