增加IJsonRead与IJsonWrite接口约束

This commit is contained in:
白茶清欢 2025-05-06 10:58:20 +08:00
parent 587a9bbe9d
commit 761058f8fe
2 changed files with 52 additions and 0 deletions

32
abstract/json_read.go Normal file
View File

@ -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
}

20
abstract/json_write.go Normal file
View File

@ -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)
}