Add simple client API, add airport type to API response
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
2025-01-12 01:12:39 -08:00
parent 54e312dccc
commit 15bc706d7a
5 changed files with 157 additions and 36 deletions

57
types/airport_type.go Normal file
View File

@@ -0,0 +1,57 @@
package types
import (
"sort"
"strings"
alphafoxtrot "github.com/grumpypixel/go-airport-finder"
)
type Airport struct {
Name string
Code string
Distance float64
Type string
data *alphafoxtrot.Airport
}
func NewAirport(airport *alphafoxtrot.Airport) *Airport {
code := strings.ToLower(airport.Country.ISOCode + airport.IATACode)
a := &Airport{
Name: airport.Name,
Code: code,
Type: airport.Type,
data: airport,
}
return a
}
func (a *Airport) String() string {
return a.Name
}
func UniqAirports(r []*Airport) []*Airport {
seen := make(map[string]struct{})
j := 0
for _, v := range r {
if _, ok := seen[v.Code]; ok {
continue
}
seen[v.Code] = struct{}{}
r[j] = v
j++
}
return r[:j]
}
func SortAirports(r []*Airport) {
sort.Slice(r, func(i, j int) bool {
if r[i].data.Type == r[j].data.Type {
return r[i].Distance < r[j].Distance
}
return r[i].data.Type < r[j].data.Type
})
}