build(deps): bump github.com/gookit/config/v2 from 2.2.6 to 2.2.7
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.6 to 2.2.7. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.6...v2.2.7) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-version: 2.2.7 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
+11
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// MustString encode data to json string, will panic on error
|
||||
@@ -62,3 +63,13 @@ func DecodeString(str string, ptr any) error {
|
||||
func DecodeReader(r io.Reader, ptr any) error {
|
||||
return json.NewDecoder(r).Decode(ptr)
|
||||
}
|
||||
|
||||
// DecodeFile decode JSON from file, bind data to ptr.
|
||||
func DecodeFile(file string, ptr any) error {
|
||||
bs, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.Unmarshal(bs, ptr)
|
||||
}
|
||||
Reference in New Issue
Block a user