65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package catalogs
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
"sync"
|
||
|
|
)
|
||
|
|
|
||
|
|
var _ = json.RawMessage{}
|
||
|
|
var _ = sync.Mutex{}
|
||
|
|
var _ = os.ReadFile
|
||
|
|
var _ = filepath.Join
|
||
|
|
|
||
|
|
type WeatherEntry4229938 struct {
|
||
|
|
Id uint32 `json:"id"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Weather catalog from WeatherConfig.json (5 entries in this build).
|
||
|
|
var (
|
||
|
|
WeatherCatalog4229938_cacheLock sync.RWMutex
|
||
|
|
WeatherCatalog4229938_cached = false
|
||
|
|
WeatherCatalog4229938_entries []any
|
||
|
|
)
|
||
|
|
|
||
|
|
// LoadWeatherCatalog4229938 loads catalog records from client config directory
|
||
|
|
func LoadWeatherCatalog4229938(configDir string) ([]any, error) {
|
||
|
|
WeatherCatalog4229938_cacheLock.RLock()
|
||
|
|
if WeatherCatalog4229938_cached {
|
||
|
|
defer WeatherCatalog4229938_cacheLock.RUnlock()
|
||
|
|
return WeatherCatalog4229938_entries, nil
|
||
|
|
}
|
||
|
|
WeatherCatalog4229938_cacheLock.RUnlock()
|
||
|
|
|
||
|
|
WeatherCatalog4229938_cacheLock.Lock()
|
||
|
|
defer WeatherCatalog4229938_cacheLock.Unlock()
|
||
|
|
if WeatherCatalog4229938_cached { return WeatherCatalog4229938_entries, nil }
|
||
|
|
|
||
|
|
filePath := filepath.Join(configDir, "WeatherCatalog.json.json")
|
||
|
|
data, err := os.ReadFile(filePath)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
var raw struct {
|
||
|
|
Records []json.RawMessage `json:"records"`
|
||
|
|
}
|
||
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
var result []any
|
||
|
|
for _, item := range raw.Records {
|
||
|
|
var m map[string]any
|
||
|
|
if err := json.Unmarshal(item, &m); err == nil {
|
||
|
|
result = append(result, m)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
WeatherCatalog4229938_entries = result
|
||
|
|
WeatherCatalog4229938_cached = true
|
||
|
|
return result, nil
|
||
|
|
}
|
||
|
|
|