Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of RPC and wallet keys fetched from env vars #1150

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"regexp"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -79,7 +80,7 @@ func ReadEnvVarSlice_String(pattern string) []string {
re := regexp.MustCompile(pattern)
var values []string

for _, env := range os.Environ() {
for _, env := range getSortedEnvs() {
pair := strings.SplitN(env, "=", 2)
if len(pair) != 2 {
continue
Expand Down Expand Up @@ -146,7 +147,7 @@ func readEnvVarValue(envVarName string, valueType EnvValueType) (interface{}, er
func readEnvVarGroupedMap(pattern string) map[string][]string {
re := regexp.MustCompile(pattern)
groupedVars := make(map[string][]string)
for _, env := range os.Environ() {
for _, env := range getSortedEnvs() {
pair := strings.SplitN(env, "=", 2)
if len(pair) != 2 {
continue
Expand All @@ -164,7 +165,7 @@ func readEnvVarGroupedMap(pattern string) map[string][]string {
func readEnvVarSingleMap(pattern string) map[string]string {
re := regexp.MustCompile(pattern)
singleVars := make(map[string]string)
for _, env := range os.Environ() {
for _, env := range getSortedEnvs() {
pair := strings.SplitN(env, "=", 2)
if len(pair) != 2 {
continue
Expand Down Expand Up @@ -212,3 +213,13 @@ const (
Boolean
Float
)

// getSortedEnvs returns a sorted slice of environment variables
func getSortedEnvs() []string {
envs := os.Environ()
// Sort environment variables by key
sort.Slice(envs, func(i, j int) bool {
return strings.SplitN(envs[i], "=", 2)[0] < strings.SplitN(envs[j], "=", 2)[0]
})
return envs
}
Loading