Config to string, JSON and YAML methods added and updated print methods to use new methods
This commit is contained in:
1 parent
e715024cbd
commit
a0fad30e99
3 files changed
+32
-33
No files matched your search
@@ -17,33 +17,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"go.yaml.in/yaml/v3"
|
||||
)
|
||||
|
||||
// Prints configuration to stdout in flat dotted format
|
||||
func (conf JobSearchConfig) PrintTerminal() {
|
||||
for k, v := range conf.Flatten() {
|
||||
typ, _ := conf.TypeOf(k)
|
||||
fmt.Print(k, " = ", v, " <", typ, ">\n")
|
||||
}
|
||||
fmt.Print(conf.String() + "\n")
|
||||
}
|
||||
|
||||
// Prints configuration to stdout as JSON
|
||||
func (conf JobSearchConfig) PrintJson() {
|
||||
confMap := conf.Map()
|
||||
jbytes, _ := json.MarshalIndent(confMap, "", " ")
|
||||
fmt.Print(string(jbytes) + "\n")
|
||||
fmt.Print(conf.JSON() + "\n")
|
||||
}
|
||||
|
||||
// Prints configuration to stdout as YAML
|
||||
func (conf JobSearchConfig) PrintYaml() {
|
||||
confMap := conf.Map()
|
||||
jbytes, _ := yaml.Marshal(confMap)
|
||||
fmt.Print(string(jbytes) + "\n")
|
||||
fmt.Print(conf.YAML() + "\n")
|
||||
}
|
||||
|
||||
// Prints configuration to logrus log at debug, info (default) or error level
|
||||
|
||||
Reference in new issue
Block a user