升级json操作, 升级为面向接口实现 #10
32
abstract/json_read.go
Normal file
32
abstract/json_read.go
Normal 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
20
abstract/json_write.go
Normal 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user