Add support for custom struct tags like `custom:"name"`
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- go
调研方向
从 expr.Env() 选项开始,跟踪 struct 字段和方法如何暴露给表达式上下文。将该行为与 protobuf 生成的 MyType 示例及其 json tags 进行比较。当可以使用基于 tag 的名称,并排除未导出的字段和重复方法时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
When passing structs to the expr.Env() option, it would be nice to have a way to modify the field extraction behavior to be able to:
- extract or map names based on tags such as the common
jsontag - ignore non-exported fields
- ignore methods
In my particular case, I'm working with protobuf-generated structs and using the expr library as a way to implement a filtering grammar similar to what is described in https://google.aip.dev/160.
Here's an example struct:
type MyType struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
CreateTime *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=create_time,json=createTime,proto3" json:"
}
func (x *MyType) GetId() string {
if x != nil {
return x.Id
}
return ""
}
/* other generated functions for exported fields */
The above struct results in both the non-exported fields and duplicate methods being made available to the expression context. It also means that the default names in the expression (prior to patching) don't match the names given in the protobuf.
- 主要语言
- Go
- 星标
- 8.1k
- 派生
- 544
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 25
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
expr-lang/expr 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 1 天内回复
-
count() without a predicate compiles for non-bool arrays and fails at run time可能已有人在做 @minilan677-netizen 于 2 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 25/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 57/100
维护者通常 1 天内回复
-
wontfix
难度 4/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
-
`find`, `findIndex`, `first` and `get` are type-checked as the element type where they return nil可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 65/100
维护者通常 1 天内回复
相似的 Issue
-
factory:subtask
难度 1/5 1 小时以内 新手友好度 95/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 95/100
OneBusAway/watchdog#470 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 1 天内回复
-
area: session
难度 2/5 1-3 小时 新手友好度 72/100
charmbracelet/crush#4484 ·
维护者通常 1 天内回复
-
accepted good first issue
难度 1/5 1-3 小时 新手友好度 95/100