From 5c78dd12014a9574efc0fd15b6a9cd2f55bb54ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 14 May 2022 15:05:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0json=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init.go | 3 +++ json.go | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/init.go b/init.go index cb88e88..de1c566 100644 --- a/init.go +++ b/init.go @@ -16,6 +16,8 @@ var ( Hash *hash // IP ... IP *ip + // JSON ... + JSON *ownJSON ) func init() { @@ -23,4 +25,5 @@ func init() { File = &file{} Hash = &hash{} IP = &ip{} + JSON = &ownJSON{} } diff --git a/json.go b/json.go index 610f916..c360d40 100644 --- a/json.go +++ b/json.go @@ -16,34 +16,42 @@ import ( "reflect" ) -// JSONUnmarshalWithNumber 解析json +// ownJSON ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 15:01 2022/5/14 +type ownJSON struct { +} + +// UnmarshalWithNumber 解析json // // Author : go_developer@163.com<白茶清欢> // // Date : 8:39 下午 2021/9/14 -func JSONUnmarshalWithNumber(byteData []byte, receiver interface{}) error { +func (oj *ownJSON) UnmarshalWithNumber(byteData []byte, receiver interface{}) error { decoder := json.NewDecoder(bytes.NewReader(byteData)) decoder.UseNumber() return decoder.Decode(receiver) } -// JSONUnmarshalWithNumberForIOReader ... +// UnmarshalWithNumberForIOReader ... // // Author : go_developer@163.com<白茶清欢> // // Date : 8:43 下午 2021/9/14 -func JSONUnmarshalWithNumberForIOReader(ioReader io.ReadCloser, receiver interface{}) error { +func (oj *ownJSON) UnmarshalWithNumberForIOReader(ioReader io.ReadCloser, receiver interface{}) error { decoder := json.NewDecoder(ioReader) decoder.UseNumber() return decoder.Decode(receiver) } -// JSONConsoleOutput ... +// ConsoleOutput ... // // Author : go_developer@163.com<白茶清欢> // // Date : 5:45 下午 2021/11/5 -func JSONConsoleOutput(data interface{}) { +func (oj *ownJSON) ConsoleOutput(data interface{}) { var out bytes.Buffer switch reflect.TypeOf(data).Kind() { case reflect.Slice: