From 022a755fdf2ff331a0418253e40e5b624e945439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 9 Jun 2022 15:25:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=BB=E5=8F=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6,=E5=B9=B6=E8=A7=A3=E6=9E=90=E5=88=B0JSON=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/file.go b/file.go index 768a00f..e2b98e8 100644 --- a/file.go +++ b/file.go @@ -43,12 +43,12 @@ func (f *file) GetProjectPath() (string, error) { return rootPath, nil } -// ReadYmlConfig 读取yml配置问价,并解析到指定的结构体中 +// ReadYmlContent 读取yml配置问价,并解析到指定的结构体中 // // Author : go_developer@163.com<白茶清欢> // // Date : 10:35 下午 2021/4/26 -func (f *file) ReadYmlConfig(filePath string, result interface{}) error { +func (f *file) ReadYmlContent(filePath string, result interface{}) error { if nil == result { return errors.New("接收读取结果的数据指针为NIL") } @@ -62,6 +62,25 @@ func (f *file) ReadYmlConfig(filePath string, result interface{}) error { return yml.Unmarshal(fileContent, result) } +// ReadJSONContent 读取JSON内容,并解析到指定的结构体中 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 15:23 2022/6/9 +func (f *file) ReadJSONContent(filePath string, result interface{}) error { + if nil == result { + return errors.New("接收读取结果的数据指针为NIL") + } + var ( + fileContent []byte + err error + ) + if fileContent, err = f.ReadFileContent(filePath); nil != err { + return err + } + return JSON.UnmarshalWithNumber(fileContent, result) +} + // ReadFileContent 读取文件内容 // // Author : go_developer@163.com<白茶清欢>