feat: 支持切片追加及 -1 头部插入
This commit is contained in:
16
reflux.go
16
reflux.go
@@ -18,6 +18,11 @@ type R interface {
|
||||
// 示例: rfx.Set("name", "Alice").Set("age", 30)
|
||||
Set(key string, v any) R
|
||||
|
||||
// Append 追加指定路径的值
|
||||
// 参数 items 为要追加的值
|
||||
// 返回当前 R 实例以支持链式调用
|
||||
Append(items ...any) R
|
||||
|
||||
// Delete 删除指定路径的值
|
||||
// 参数 p 为路径片段
|
||||
// 返回当前 R 实例以支持链式调用
|
||||
@@ -123,7 +128,7 @@ type R interface {
|
||||
// - 如果传入指针: 将直接使用该指针,可以修改原始数据
|
||||
// - 如果传入值: 会自动创建一个深度克隆的指针副本,修改不影响原始数据
|
||||
// 支持的类型: map、struct、slice、array
|
||||
// 也支持 interface 类型,会自动解析到实际类型
|
||||
// 也支持 interface 类型以及部分基础类型(string/bool/float),会自动解析到实际类型
|
||||
// 返回一个 R 接口实例,可用于访问和操作嵌套的字段、元素和键值对
|
||||
func New(v any) R {
|
||||
rv := reflect.ValueOf(v)
|
||||
@@ -150,7 +155,14 @@ func New(v any) R {
|
||||
|
||||
// 检查最终的实际类型是否为支持的类型
|
||||
switch actualValue.Kind() {
|
||||
case reflect.Map, reflect.Struct, reflect.Slice, reflect.Array:
|
||||
case reflect.Map,
|
||||
reflect.Struct,
|
||||
reflect.Slice,
|
||||
reflect.Array,
|
||||
reflect.String,
|
||||
reflect.Bool,
|
||||
reflect.Float32,
|
||||
reflect.Float64:
|
||||
// 支持的类型
|
||||
default:
|
||||
panic("rfx: unsupported type, only map, struct, slice, and array are allowed")
|
||||
|
||||
Reference in New Issue
Block a user