mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-05 05:20:34 +00:00
yaml config
This commit is contained in:
@@ -113,7 +113,6 @@ require (
|
||||
google.golang.org/grpc v1.64.1 // indirect
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -129,4 +128,5 @@ require (
|
||||
github.com/swaggo/gin-swagger v1.6.0
|
||||
github.com/swaggo/swag v1.16.3
|
||||
go.etcd.io/etcd/client/v3 v3.5.15
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
+15
-2
@@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/DisposaBoy/JsonConfigReader"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
)
|
||||
|
||||
// ConfigStructure is structure of main configuration
|
||||
@@ -194,8 +196,19 @@ func LoadConfig(filename string, config *ConfigStructure) error {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
dec := json.NewDecoder(JsonConfigReader.New(f))
|
||||
return dec.Decode(&config)
|
||||
dec_json := json.NewDecoder(JsonConfigReader.New(f))
|
||||
if err = dec_json.Decode(&config); err != nil {
|
||||
f.Seek(0, 0)
|
||||
dec_yaml := yaml.NewDecoder(f)
|
||||
if err = dec_yaml.Decode(&config); err != nil {
|
||||
fmt.Errorf("config file %s is not valid yaml or json\n", filename)
|
||||
} else {
|
||||
fmt.Printf("config file %s format is yaml\n", filename)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("config file %s format is json\n", filename)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// SaveConfig write configuration to json file
|
||||
|
||||
Reference in New Issue
Block a user