mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-28 18:41:30 +02:00
Service entry points currently resolve defaults, files, environment variables, and flags differently, which makes precedence inconsistent and prevents some services from using config files. Introduce one Viper-backed loader and migrate Combined, Management, Relay, Signal, and Proxy while preserving compatibility aliases and Management template expansion.
35 lines
776 B
Go
35 lines
776 B
Go
package config
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"text/template"
|
|
)
|
|
|
|
// ExpandEnvTemplate substitutes Go-template references with environment values.
|
|
func ExpandEnvTemplate(data []byte) ([]byte, error) {
|
|
tmpl, err := template.New("config").Parse(string(data))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("parse environment template: %w", err)
|
|
}
|
|
|
|
var output bytes.Buffer
|
|
if err := tmpl.Execute(&output, environmentMap()); err != nil {
|
|
return nil, fmt.Errorf("execute environment template: %w", err)
|
|
}
|
|
return output.Bytes(), nil
|
|
}
|
|
|
|
func environmentMap() map[string]string {
|
|
environment := make(map[string]string)
|
|
for _, entry := range os.Environ() {
|
|
key, value, ok := strings.Cut(entry, "=")
|
|
if ok {
|
|
environment[key] = value
|
|
}
|
|
}
|
|
return environment
|
|
}
|