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 (
|
|
|
|
createAccountPath = "/api/v2/account/create"
|
|
|
|
trackStatusPath = "/api/track"
|
|
|
|
balancePathPrefix = "/api/account"
|
|
|
|
trackPath = "/api/v2/account/status"
|
|
|
|
voucherHoldingsPathPrefix = "/api/v1/holdings"
|
|
|
|
voucherTransfersPathPrefix = "/api/v1/transfers/last10"
|
2024-11-03 15:34:26 +01:00
|
|
|
voucherDataPathPrefix = "/api/v1/token"
|
2024-10-31 02:28:37 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
custodialURLBase string
|
|
|
|
dataURLBase string
|
|
|
|
CustodialAPIKey string
|
|
|
|
DataAPIKey string
|
|
|
|
)
|
2024-08-26 11:09:48 +02:00
|
|
|
|
2024-10-15 22:41:16 +02:00
|
|
|
var (
|
|
|
|
CreateAccountURL string
|
|
|
|
TrackStatusURL string
|
2024-10-31 02:28:37 +01:00
|
|
|
BalanceURL string
|
|
|
|
TrackURL string
|
|
|
|
VoucherHoldingsURL string
|
|
|
|
VoucherTransfersURL string
|
2024-11-03 15:34:26 +01:00
|
|
|
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")
|
|
|
|
CustodialAPIKey = initializers.GetEnv("CUSTODIAL_API_KEY", "xd")
|
|
|
|
DataAPIKey = initializers.GetEnv("DATA_API_KEY", "xd")
|
|
|
|
|
|
|
|
_, 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
|
|
|
|
}
|
|
|
|
CreateAccountURL, _ = url.JoinPath(custodialURLBase, createAccountPath)
|
|
|
|
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
|
|
|
}
|