try fuck log config

This commit is contained in:
kongfei 2022-06-01 23:54:45 +08:00
parent 74c5ae30a4
commit f9ab1e6e66
1 changed files with 22 additions and 2 deletions

View File

@ -1,8 +1,11 @@
package config
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"path"
logsconfig "flashcat.cloud/categraf/config/logs"
@ -59,13 +62,30 @@ func InitLogConfig(configDir string) error {
}
func loadLogConfig(file string) (*Logs, error) {
// v := viper.New()
// v.SetConfigFile(file)
// err := v.ReadInConfig()
// if err != nil {
// return nil, err
// }
// l := Logs{}
// err = v.Unmarshal(&l)
// if err != nil {
// return nil, err
// }
// return &l, nil
v := viper.New()
v.SetConfigFile(file)
err := v.ReadInConfig()
data, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
log.Printf("%s\n", data)
l := Logs{}
v.SetConfigType("toml")
err = v.ReadConfig(bytes.NewBuffer(data))
if err != nil {
return nil, err
}
err = v.Unmarshal(&l)
if err != nil {
return nil, err