MCPcopy Index your code
hub / github.com/aptly-dev/aptly / LoadConfig

Function LoadConfig

utils/config.go:284–304  ·  view source on GitHub ↗

LoadConfig loads configuration from json file

(filename string, config *ConfigStructure)

Source from the content-addressed store, hash-verified

282
283// LoadConfig loads configuration from json file
284func LoadConfig(filename string, config *ConfigStructure) error {
285 f, err := os.Open(filename)
286 if err != nil {
287 return err
288 }
289 defer func() {
290 _ = f.Close()
291 }()
292
293 decJSON := json.NewDecoder(JsonConfigReader.New(f))
294 if err = decJSON.Decode(&config); err != nil {
295 _, _ = f.Seek(0, 0)
296 decYAML := yaml.NewDecoder(f)
297 if err2 := decYAML.Decode(&config); err2 != nil {
298 err = fmt.Errorf("invalid yaml (%s) or json (%s)", err2, err)
299 } else {
300 err = nil
301 }
302 }
303 return err
304}
305
306// SaveConfig write configuration to json file
307func SaveConfig(filename string, config *ConfigStructure) error {

Callers 6

configMethod · 0.92
TestLoadConfigMethod · 0.85
TestLoadYAMLConfigMethod · 0.85
TestSaveYAMLConfigMethod · 0.85
TestLoadEmptyConfigMethod · 0.85

Calls 3

OpenMethod · 0.65
CloseMethod · 0.65
DecodeMethod · 0.45

Tested by 5

TestLoadConfigMethod · 0.68
TestLoadYAMLConfigMethod · 0.68
TestSaveYAMLConfigMethod · 0.68
TestLoadEmptyConfigMethod · 0.68