2020-08-25 19:38:50 -04:00
|
|
|
package constants
|
|
|
|
|
|
2021-07-20 03:01:26 +00:00
|
|
|
import (
|
|
|
|
|
_ "embed"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//go:embed servers.json
|
|
|
|
|
var allServersBytes []byte //nolint:gochecknoglobals
|
|
|
|
|
var allServers models.AllServers //nolint:gochecknoglobals
|
|
|
|
|
|
|
|
|
|
func init() { //nolint:gochecknoinits
|
|
|
|
|
// error returned covered by unit test
|
|
|
|
|
allServers, _ = parseAllServers(allServersBytes)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseAllServers(b []byte) (allServers models.AllServers, err error) {
|
|
|
|
|
err = json.Unmarshal(b, &allServers)
|
|
|
|
|
return allServers, err
|
|
|
|
|
}
|
2020-08-25 19:38:50 -04:00
|
|
|
|
|
|
|
|
func GetAllServers() (allServers models.AllServers) {
|
2021-07-20 03:01:26 +00:00
|
|
|
if allServers.Version == 0 { // not parsed yet - for unit tests mostly
|
|
|
|
|
allServers, _ = parseAllServers(allServersBytes)
|
2020-08-25 19:38:50 -04:00
|
|
|
}
|
2021-07-20 03:01:26 +00:00
|
|
|
return allServers
|
2020-08-25 19:38:50 -04:00
|
|
|
}
|