github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/utils/yaml.go (about) 1 // Ultimate Provisioner: UP cmd 2 // Copyright (c) 2019 Stephen Cheng and contributors 3 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 7 8 package utils 9 10 import ( 11 "fmt" 12 "github.com/spf13/viper" 13 "os" 14 ) 15 16 func YamlLoader(id, path, filename string) *viper.Viper { 17 Pf("loading [%s]: %s/%s\n", id, path, filename) 18 newV := viper.New() 19 newV.AddConfigPath(path) 20 newV.SetConfigType("yaml") 21 newV.SetConfigName(filename) 22 23 err := newV.ReadInConfig() 24 25 if err != nil { 26 fmt.Printf("yml dir: %s\n", path) 27 fmt.Printf("yml file: %s\n", filename) 28 fmt.Println("errored:", err.Error()) 29 LogError("Yaml loading error", err) 30 DebugYmlContent(path, filename) 31 os.Exit(3) 32 } 33 34 return newV 35 } 36 37