Add VRNP_CLIENT_ALLOWLIST env var
This commit is contained in:
parent
5d5b893948
commit
6e78235127
22
main.go
22
main.go
@ -51,6 +51,12 @@ type EFAClient interface {
|
||||
BuildRequest(string) (*http.Request, error)
|
||||
}
|
||||
|
||||
var allEfaClients []EFAClient = []EFAClient{
|
||||
BwegtEFAClient{},
|
||||
VRNEFAClient{},
|
||||
KVVEFAClient{},
|
||||
}
|
||||
|
||||
type VRNEFAClient struct {
|
||||
}
|
||||
|
||||
@ -181,7 +187,7 @@ type Departure struct {
|
||||
Symbol string `json:"symbol"`
|
||||
Direction string `json:"direction"`
|
||||
Leaving string `json:"leaving"`
|
||||
Countdown int
|
||||
Countdown int `json:"-"`
|
||||
}
|
||||
|
||||
func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures, error) {
|
||||
@ -240,15 +246,18 @@ func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures,
|
||||
func main() {
|
||||
password := os.Getenv("VRNP_PASSWORD")
|
||||
if len(password) == 0 {
|
||||
panic("Required environment variable VRNP_PASSWORD is not set")
|
||||
log.Fatal("Required environment variable VRNP_PASSWORD is not set")
|
||||
}
|
||||
|
||||
clientAllowlist := strings.Split(os.Getenv("VRNP_CLIENT_ALLOWLIST"), ",")
|
||||
|
||||
// Use round-robin to send incoming requests to different servers
|
||||
var efaClient atomic.Uint64
|
||||
efaClients := []EFAClient{
|
||||
BwegtEFAClient{},
|
||||
VRNEFAClient{},
|
||||
KVVEFAClient{},
|
||||
var efaClients []EFAClient
|
||||
for _, efaClient := range allEfaClients {
|
||||
if len(clientAllowlist) != 0 && slices.Contains(clientAllowlist, efaClient.GetName()) {
|
||||
efaClients = append(efaClients, efaClient)
|
||||
}
|
||||
}
|
||||
|
||||
http.HandleFunc("/departures", func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -273,7 +282,6 @@ func main() {
|
||||
}
|
||||
|
||||
c := efaClients[(efaClient.Add(1) - 1) % uint64(len(efaClients))]
|
||||
log.Print(c.GetName())
|
||||
ds, err := FetchDepartures(c, stopId)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
Loading…
x
Reference in New Issue
Block a user