2024-12-28 15:10:57 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2024-12-28 16:03:00 +00:00
|
|
|
"fmt"
|
|
|
|
|
2024-12-28 15:10:57 +00:00
|
|
|
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
|
|
"github.com/rs/zerolog/log"
|
2024-12-28 16:15:59 +00:00
|
|
|
"github.com/spf13/cast"
|
2024-12-28 15:10:57 +00:00
|
|
|
"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)
|
2024-12-28 15:10:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func BuildDestinationMapping() {
|
2024-12-28 16:15:59 +00:00
|
|
|
count := len(cast.ToSlice(viper.Get("destinations")))
|
2024-12-28 16:03:00 +00:00
|
|
|
for idx := 0; idx < count; idx++ {
|
2024-12-28 16:15:59 +00:00
|
|
|
fmt.Println(idx)
|
2024-12-28 16:03:00 +00:00
|
|
|
destMap := viper.GetStringMap(fmt.Sprintf("destinations.%d", idx))
|
2024-12-28 15:10:57 +00:00
|
|
|
var parsed models.BaseDestination
|
2024-12-28 16:03:00 +00:00
|
|
|
raw, _ := jsoniter.Marshal(destMap)
|
2024-12-28 15:10:57 +00:00
|
|
|
_ = 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
|
2024-12-28 15:10:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info().Int("count", count).Msg("Destinations mapping built")
|
|
|
|
}
|