ussd/config/config.go

71 lines
1.9 KiB
Go
Raw Permalink Normal View History

2024-08-26 11:09:48 +02:00
package config
2024-10-31 02:28:37 +01:00
import (
"net/url"
"git.grassecon.net/urdt/ussd/initializers"
)
const (
2024-11-13 14:16:32 +01:00
createAccountPath = "/api/v2/account/create"
trackStatusPath = "/api/track"
balancePathPrefix = "/api/account"
trackPath = "/api/v2/account/status"
voucherHoldingsPathPrefix = "/api/v1/holdings"
2024-10-31 02:28:37 +01:00
voucherTransfersPathPrefix = "/api/v1/transfers/last10"
2024-11-13 14:16:32 +01:00
voucherDataPathPrefix = "/api/v1/token"
2024-10-31 02:28:37 +01:00
)
var (
2024-11-13 14:16:32 +01:00
custodialURLBase string
dataURLBase string
CustodialBearerToken string
DataBearerToken string
2024-10-31 02:28:37 +01:00
)
2024-08-26 11:09:48 +02:00
2024-10-15 22:41:16 +02:00
var (
2024-11-13 14:16:32 +01:00
CreateAccountURL string
TrackStatusURL string
BalanceURL string
TrackURL string
VoucherHoldingsURL string
VoucherTransfersURL string
VoucherDataURL string
2024-08-26 12:38:14 +02:00
)
2024-08-26 11:09:48 +02:00
2024-10-31 02:28:37 +01:00
func setBase() error {
var err error
custodialURLBase = initializers.GetEnv("CUSTODIAL_URL_BASE", "http://localhost:5003")
dataURLBase = initializers.GetEnv("DATA_URL_BASE", "http://localhost:5006")
2024-11-13 14:16:32 +01:00
CustodialBearerToken = initializers.GetEnv("CUSTODIAL_BEARER_TOKEN", "")
DataBearerToken = initializers.GetEnv("DATA_BEARER_TOKEN", "")
2024-10-31 02:28:37 +01:00
_, err = url.JoinPath(custodialURLBase, "/foo")
if err != nil {
return err
}
_, err = url.JoinPath(dataURLBase, "/bar")
if err != nil {
return err
}
return nil
}
2024-10-15 22:41:16 +02:00
// LoadConfig initializes the configuration values after environment variables are loaded.
2024-10-31 02:28:37 +01:00
func LoadConfig() error {
err := setBase()
if err != nil {
return err
}
2024-11-13 14:16:32 +01:00
CreateAccountURL, _ = url.JoinPath(custodialURLBase, createAccountPath)
2024-10-31 02:28:37 +01:00
TrackStatusURL, _ = url.JoinPath(custodialURLBase, trackStatusPath)
BalanceURL, _ = url.JoinPath(custodialURLBase, balancePathPrefix)
TrackURL, _ = url.JoinPath(custodialURLBase, trackPath)
VoucherHoldingsURL, _ = url.JoinPath(dataURLBase, voucherHoldingsPathPrefix)
VoucherTransfersURL, _ = url.JoinPath(dataURLBase, voucherTransfersPathPrefix)
2024-11-03 15:34:26 +01:00
VoucherDataURL, _ = url.JoinPath(dataURLBase, voucherDataPathPrefix)
2024-10-31 02:28:37 +01:00
return nil
2024-10-15 22:41:16 +02:00
}