Paperclip/pkg/internal/services/destinations.go

45 lines
955 B
Go
Raw Normal View History

package services
import (
2024-12-28 16:03:00 +00:00
"fmt"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
jsoniter "github.com/json-iterator/go"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
type destinationMapping struct {
Index int
Raw []byte
}
var (
2024-12-28 16:03:00 +00:00
DestinationsByIndex = make(map[int]destinationMapping)
DestinationsByRegion = make(map[string]destinationMapping)
)
func BuildDestinationMapping() {
2024-12-28 16:03:00 +00:00
count := len(viper.GetStringSlice("destinations"))
for idx := 0; idx < count; idx++ {
destMap := viper.GetStringMap(fmt.Sprintf("destinations.%d", idx))
var parsed models.BaseDestination
2024-12-28 16:03:00 +00:00
raw, _ := jsoniter.Marshal(destMap)
_ = jsoniter.Unmarshal(raw, &parsed)
mapping := destinationMapping{
Index: idx,
Raw: raw,
}
if len(parsed.Region) > 0 {
2024-12-28 16:03:00 +00:00
DestinationsByIndex[idx] = mapping
DestinationsByRegion[parsed.Region] = mapping
}
count++
}
log.Info().Int("count", count).Msg("Destinations mapping built")
}