From 761058f8fe811e2b6829ce41db729cd89f82ec8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 6 May 2025 10:58:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0IJsonRead=E4=B8=8EIJsonWrite?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abstract/json_read.go | 32 ++++++++++++++++++++++++++++++++ abstract/json_write.go | 20 ++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 abstract/json_read.go create mode 100644 abstract/json_write.go diff --git a/abstract/json_read.go b/abstract/json_read.go new file mode 100644 index 0000000..0e824e8 --- /dev/null +++ b/abstract/json_read.go @@ -0,0 +1,32 @@ +// Package abstract ... +// +// Description : abstract ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2025-05-06 10:42 +package abstract + +// IJsonRead json数据读取接口约束 +type IJsonRead interface { + // Exist 指定路径是否存在 + Exist(dataPath string) bool + // IsNil 指定路径是否为nil + IsNil(dataPath string) bool + // Int 转换为int类型 + Int(dataPath string) (int, error) + // Uint 转换为uint类型 + Uint(dataPath string) (uint, error) + // Float 转换为float类型 + Float(dataPath string) (float64, error) + // String 转换为string类型 + String(dataPath string) (string, error) + // Map 转换为map + Map(dataPath string) (map[string]any, error) + // MapWithReceiver 通过指针接收 + MapWithReceiver(dataPath string, receiver any) error + // Array 转换为数组 + Array(dataPath string) ([]any, error) + // ArrayWithReceiver 通过指针接收 + ArrayWithReceiver(dataPath string, receiver any) error +} diff --git a/abstract/json_write.go b/abstract/json_write.go new file mode 100644 index 0000000..da7fb2d --- /dev/null +++ b/abstract/json_write.go @@ -0,0 +1,20 @@ +// Package abstract ... +// +// Description : abstract ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2025-05-06 10:53 +package abstract + +// IJsonWrite json数据写入 +type IJsonWrite interface { + // Set 设置一个路径的值 + Set(dataPath string, data interface{}) error + // Result 最终结果以字符串形式返回 + Result() string + // Map 最终结果以map返回 + Map() (map[string]any, error) + // Array 最终结果以数组返回 + Array() ([]any, error) +}