Description
Expression language(EL) to manipulate Golang structure data. Its main purpose is to find reflect.Value by Expression, then do some reading and writing.
go-el alternatives and similar packages
Based on the "Utilities" category.
Alternatively, view go-el alternatives based on common mentions on social networks and blogs.
-
项目文档
基于vite+vue3+gin搭建的开发基础平台(支持TS,JS混用),集成jwt鉴权,权限管理,动态路由,显隐可控组件,分页封装,多点登录拦截,资源权限,上传下载,代码生成器,表单生成器,chatGPT自动查表等开发必备功能。 -
excelize
Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets -
xlsx
(No longer maintained!) Go (golang) library for reading and writing XLSX files. -
godotenv
A Go port of Ruby's dotenv library (Loads environment variables from .env files) -
hystrix-go
Netflix's Hystrix latency and fault tolerance library, for Go -
go-funk
A modern Go utility library which provides helpers (map, find, contains, filter, ...) -
gorequest
GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent ) -
Kopia
Cross-platform backup tool for Windows, macOS & Linux with fast, incremental backups, client-side end-to-end encryption, compression and data deduplication. CLI and GUI included. -
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report. -
gojson
Automatically generate Go (golang) struct definitions from example JSON -
lancet
A comprehensive, efficient, and reusable util function library of Go. -
create-go-app
✨ Create a new production-ready project with backend, frontend and deploy automation by running one CLI command! -
spinner
Go (golang) package with 90 configurable terminal spinner/progress indicators. -
filetype
Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature -
EaseProbe
A simple, standalone, and lightweight tool that can do health/status checking, written in Go. -
boilr
:zap: boilerplate template manager that generates files or directories from template repositories -
mole
CLI application to create ssh tunnels focused on resiliency and user experience. -
beaver
💨 A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps. -
mimetype
A fast Golang library for media type and file extension detection, based on magic numbers -
go-underscore
Helpfully Functional Go - A useful collection of Go utilities. Designed for programmer happiness. -
JobRunner
Framework for performing work asynchronously, outside of the request flow -
git-time-metric
Simple, seamless, lightweight time tracking for Git
Access the most powerful time series database as a service
Do you think we are missing an alternative of go-el or a related project?
Popular Comparisons
README
go-el
Expression language(EL) to manipulate Golang structure data. Its main purpose is to find reflect.Value
by Expression, then do some reading and writing.
Installation
Simple as it takes to type the following command:
go get github.com/lysu/go-el
and import with
import github.com/lysu/go-el
Usage
Example Data
As example, we have some data like this:
type Comment struct {
NickName string
Content string
Date time.Time
}
type Author struct {
Name string
}
type Blog struct {
Title string
RoleState map[string]uint
CommentIds []uint64
Comments map[string]*Comment
}
func (b Blog) FirstComment() *Comment {
return b.Comments["0"]
}
then we init them with some test data:
b := &Blog{
Title: "Blog title1",
CommentIds: []uint64{1, 3},
Comments: map[string]*Comment{
"0": {
NickName: "000",
Content: "test",
Date: time.Now(),
},
"1": {
NickName: "u1",
Content: "test",
Date: time.Now(),
},
"3": {
NickName: "tester",
Content: "test hehe...",
Date: time.Now(),
},
},
Author: Author{
Name: "Author 1",
},
RoleState: map[string]uint{},
}
Expression
Using el.Expression
, we can navigate from root(b
) to anywhere in this structure.
1. To field
exp := el.Expression("Title")
v, _ := exp.Execute(&data)
fmt.Printf("%v\n", v.interface()) //==> Blog title1
2. To nested field
exp := el.Expression("Author.Name")
v, _ := exp.Execute(&data)
fmt.Printf("%v\n", v.interface()) //==> Author 1
3. To slice/array/string item
exp := el.Expression("CommentIds[0]")
v, _ := exp.Execute(&data)
fmt.Printf("%v\n", v.interface()) //==> 1
4. To map item
exp := el.Expression("Comments["3"].NickName")
v, _ := exp.Execute(&data)
fmt.Printf("%v\n", v.interface()) //==> tester
5. Item in[]
also can be another Expression
exp := el.Expression("Comments["CommentIds[0]].NickName")
v, _ := exp.Execute(&data)
fmt.Printf("%v\n", v.interface()) //==> u1
6. Call function
function can return only ONE
result
exp := el.Expression("FirstComment().Content")
v, _ := exp.Execute(&data)
fmt.Printf("%v\n", v.interface()) //==> test
7. Modify Value
After Execute
expression, we got a relfect.Value
, we also can use it to modify data, e.g.
exp := el.Expression("FirstComment().Content")
v, _ := exp.Execute(&data)
v.SetString("1111")
will let first comment with value 1111
Beside that we recommend users take a moment to look The Laws of Reflection, take care some limition that reflect has.
Patcher
Base on Expression, we also provide a tool named Patcher
, the purpose of it is to let use modify object with expression easier and be batched.
We found it's very useful to build HTTP Patch API to partial update entity
ps := p.Patch{
"Author.Name": "ほん",
"Comments[CommentIds[0]].NickName": "私",
"roleState[100]": uint(100),
}
err := patcher.PatchIt(b, ps)
This will modify three properties at once~ (but we still meet some rule of refect, like map-value use ptr.. and so on)
More
See our Example in Unit-Test:
TODO
generate expression between two data..like diff..- -?
Thanks
- Many code was extract from flosch/pongo2 --- An cool template-engine
- The presentation by Rob Pike titled Lexical Scanning in Go