diff --git a/file.go b/file.go index 39d619b..b0b4740 100644 --- a/file.go +++ b/file.go @@ -14,6 +14,8 @@ import ( "path/filepath" "strings" + "github.com/BurntSushi/toml" + "git.zhangdeman.cn/zhangdeman/util/define" "github.com/go-ini/ini" @@ -99,6 +101,21 @@ func (f *file) ReadIniContent(filePath string, result interface{}) error { return ini.MapTo(result, filePath) } +// ReadTomlContent 读取toml格式文件 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:08 2023/7/31 +func (f *file) ReadTomlContent(filePath string, result interface{}) error { + if nil == result { + return errors.New("接收读取结果的数据指针为NIL") + } + if _, err := toml.DecodeFile("example.toml", result); err != nil { + return err + } + return nil +} + // ReadAnyFileContent 读取任意类型的文件并解析 // // Author : go_developer@163.com<白茶清欢> diff --git a/go.mod b/go.mod index a4b4065..87dfdf3 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( ) require ( + github.com/BurntSushi/toml v1.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/tidwall/match v1.1.1 // indirect diff --git a/go.sum b/go.sum index da9d2ca..d7e84c4 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo= github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc= github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=