refactor: switch config format from YAML to TOML
- Replace gopkg.in/yaml.v3 with github.com/BurntSushi/toml - Update struct tags from yaml to toml - Update config tests to use TOML syntax - Add testdata/config.toml, update Helm configmap template
This commit is contained in:
+19
-19
@@ -6,39 +6,39 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Server ServerConfig `yaml:"server"`
|
||||
Git GitConfig `yaml:"git"`
|
||||
Cluster ClusterConfig `yaml:"cluster"`
|
||||
ToolchainRegistry string `yaml:"toolchain_registry"`
|
||||
TargetRepoTemplate string `yaml:"target_repo_template"`
|
||||
Plugins []PluginConfig `yaml:"plugins"`
|
||||
Server ServerConfig `toml:"server"`
|
||||
Git GitConfig `toml:"git"`
|
||||
Cluster ClusterConfig `toml:"cluster"`
|
||||
ToolchainRegistry string `toml:"toolchain_registry"`
|
||||
TargetRepoTemplate string `toml:"target_repo_template"`
|
||||
Plugins []PluginConfig `toml:"plugins"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
Addr string `yaml:"addr"`
|
||||
PublicURL string `yaml:"public_url"`
|
||||
Addr string `toml:"addr"`
|
||||
PublicURL string `toml:"public_url"`
|
||||
}
|
||||
|
||||
type GitConfig struct {
|
||||
Type string `yaml:"type"`
|
||||
BaseURL string `yaml:"base_url"`
|
||||
Token string `yaml:"token"`
|
||||
Type string `toml:"type"`
|
||||
BaseURL string `toml:"base_url"`
|
||||
Token string `toml:"token"`
|
||||
}
|
||||
|
||||
type ClusterConfig struct {
|
||||
Kubeconfig string `yaml:"kubeconfig"`
|
||||
Namespace string `yaml:"namespace"`
|
||||
JobTimeout int `yaml:"job_timeout"`
|
||||
MaxConcurrent int `yaml:"max_concurrent"`
|
||||
Kubeconfig string `toml:"kubeconfig"`
|
||||
Namespace string `toml:"namespace"`
|
||||
JobTimeout int `toml:"job_timeout"`
|
||||
MaxConcurrent int `toml:"max_concurrent"`
|
||||
}
|
||||
|
||||
type PluginConfig struct {
|
||||
Language string `yaml:"language"`
|
||||
Image string `yaml:"image"`
|
||||
Language string `toml:"language"`
|
||||
Image string `toml:"image"`
|
||||
}
|
||||
|
||||
var envVarRegex = regexp.MustCompile(`\$\{(\w+)\}`)
|
||||
@@ -52,7 +52,7 @@ func Load(path string) (*Config, error) {
|
||||
expanded := expandEnvVars(string(data))
|
||||
|
||||
var cfg Config
|
||||
if err := yaml.Unmarshal([]byte(expanded), &cfg); err != nil {
|
||||
if _, err := toml.Decode(expanded, &cfg); err != nil {
|
||||
return nil, fmt.Errorf("parsing config: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user