All Projects → lysu → go-el

lysu / go-el

Licence: other
Expression language(EL) to navigate/manipulate in golang structure data

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-el

IOS-Patcher
Patches the RSA Key and applies mail patches in IOS31 and IOS80 on the Wii so you can use RiiConnect24.
Stars: ✭ 17 (-59.52%)
Mutual labels:  patcher
pepatch
A hacky tool to patch PE binaries.
Stars: ✭ 21 (-50%)
Mutual labels:  patcher
patchmanager
Patchmanager for SailfishOS
Stars: ✭ 21 (-50%)
Mutual labels:  patcher
Patch Package
Fix broken node modules instantly 🏃🏽‍♀️💨
Stars: ✭ 6,062 (+14333.33%)
Mutual labels:  patcher
OS-X-Yosemite-on-Unsupported-Macs
Install OS X Yosemite on Unsupported Macs
Stars: ✭ 23 (-45.24%)
Mutual labels:  patcher
UnofficialCrusaderPatch
Unofficial balancing patch installer for Stronghold Crusader 1
Stars: ✭ 373 (+788.1%)
Mutual labels:  patcher
tingle
Tingle - Android patcher
Stars: ✭ 150 (+257.14%)
Mutual labels:  patcher
JitCat
A C++17 library for parsing and executing expressions. Allows easy exposure of variables and functions from C++ through built-in reflection functionality.
Stars: ✭ 16 (-61.9%)
Mutual labels:  expression-language
textomatic
Scratchpad for tabular data transformations
Stars: ✭ 27 (-35.71%)
Mutual labels:  expression-language
xdelta3-cross-gui
A cross-platform GUI for creating xDelta3 patches, available for Windows, Linux, and Mac
Stars: ✭ 50 (+19.05%)
Mutual labels:  patcher
Nerd Fonts
Iconic font aggregator, collection, & patcher. 3,600+ icons, 50+ patched fonts: Hack, Source Code Pro, more. Glyph collections: Font Awesome, Material Design Icons, Octicons, & more
Stars: ✭ 31,778 (+75561.9%)
Mutual labels:  patcher
lazy ips
IPS patcher for Linux
Stars: ✭ 39 (-7.14%)
Mutual labels:  patcher
PATCH
The PATCH repository for issues tracking, wiki and shared material.
Stars: ✭ 34 (-19.05%)
Mutual labels:  patcher
Oxide.Patcher
IL patcher for use with adding Oxide support to .NET games
Stars: ✭ 27 (-35.71%)
Mutual labels:  patcher
UniversalUnityHooks
A framework designed to hook into and modify methods in unity games via dlls
Stars: ✭ 78 (+85.71%)
Mutual labels:  patcher
AzulPatcher4600
Lilu plugin which applies common patches for the mobile HD4600 iGPU
Stars: ✭ 17 (-59.52%)
Mutual labels:  patcher
MacOS-All-In-One-Update-Script
Mac update shell script (Appstore, macOS, Homebrew and others)
Stars: ✭ 39 (-7.14%)
Mutual labels:  patcher
DotNetUniversalPatcher
A .NET Patcher written in C# that implements the dnlib and dnpatch libraries.
Stars: ✭ 54 (+28.57%)
Mutual labels:  patcher
OpenCore-Legacy-Patcher
Experience macOS just like before
Stars: ✭ 2,733 (+6407.14%)
Mutual labels:  patcher
FC2MPPatcher
A community-made utility for patching Far Cry 2 to yet again support multiplayer online.
Stars: ✭ 25 (-40.48%)
Mutual labels:  patcher

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].