a decision & trigger framework backed by Google's Common Expression Language used in graphikDB

trigger

https://graphikdb.github.io/trigger/

GoDoc

a decision & trigger framework backed by Google's Common Expression Language used in graphikDB

  • Full Text Search Expression Macros/Functions(startsWith, endsWith, contains)
  • RegularExp Expression Macros/Functions(matches)
  • Geographic Expression Macros/Functions(geoDistance)
  • Cryptographic Expression Macros/Functions(encrypt, decrypt, sha1, sha256, sha3)
  • JWT Expression Macros/Functions(parseClaims, parseHeader, parseSignature)
  • Collection Expression Macros/Functions(in, map, filter, exists)
  • String Manipulation Expression Macros/Functions(replace, join, titleCase, lowerCase, upperCase, trimSpace, trimPrefix, trimSuffix, render)
  • URL Introspection Expression Macros/Functions(parseHost, parseScheme, parseQuery, parsePath)

Use Case:

Since this expression language requires just input data(map[string]interface) and an expression string, Go programs may use it to embed flexible logic that may be changed at runtime without having to recompile.

  • Authorization Middleware/Policy Evaluation/Rule Engine

  • Database or API "triggers" for mutating data before its commited

  • Search Engine(filter something based on a decision)

Examples

restrict access based on domain

	decision, err := trigger.NewDecision("this.email.endsWith('acme.com')")
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	err = decision.Eval(map[string]interface{}{
		"email": "[email protected]",
	})
	fmt.Println(err == trigger.ErrDecisionDenied) 
    // Output: true 

create a trigger based on signup event that adds updated_at timestamp & hashes a password

	// create a trigger based on the new decision that hashes a password and creates an updated_at timestamp
	// this would in theory be applied to a newly created user after signup
	trigg, err := trigger.NewArrowTrigger(`
	this.event == 'signup' && has(this.email) =>
	{
		'updated_at': now(),
		'password': this.password.sha1()
	}
`)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	user := map[string]interface{}{
		"event": "signup",
		"name":  "bob",
		"email": "[email protected]",
		"password": "123456",
	}
	data, err := trigg.Trigger(user)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(data["updated_at"].(int64) > 0, data["password"])
	// Output: true 7c4a8d09ca3762af61e59520943dc26494f8941b

CEL Macro Extensions

Additional details on the standard CEL spec/library may be found here

function notation description
now now() int64 current timestamp in unix secods
uuid uuid() string random uuidv4 string
sha1 sha1(string) string sha1 hash of the input string
sha256 sha256(string) string sha256 hash of the input string
sha3 sha3(string) string sha3 hash of the input string
base64Encode base64Encode(string) string base64 encoded version of the input
base64Decode base64Decode(string) string base64 decoded version of the input
jsonEncode jsonEncode(string) string json encoded version of the input
jsonDecode jsonDecode(string) string json decoded version of the input
replace replace(text string, old string, new string) string full string replacement of the old value with the new value
join join(arr list(string), sep string) string joins the array into a single string with the given separator
titleCase titleCase(string) string converts the input into title case string
lowerCase lowerCase(string) string converts the input into lower case string
upperCase upperCase(string) string converts the input into upper case string
trimSpace trimSpace(string) string removes white spaces from the input string
trimPrefix trimPrefix(string) string removes prefix from the input string
trimSuffix trimSuffix(string) string removes suffix from the input string
geoDistance geoDistance(this list(float64), that list(float64)) float64 haversine distance between two coordinates [lat,lng]
render render(tmplate string, data map[string]interface) string renders the input template with the provided data map
parseClaims parseClaims(jwt string) map[string]interface) returns the payload of the jwt as a map
parseHeader parseHeader(jwt string) map[string]interface returns the header of the jwt as a map
parseSignature parseSignature(jwt string) string returns the signature of the jwt as a string
typeOf typeOf(any) string returns the go type of the input
encrypt encrypt(secret string, msg string) string aes encrypt a message with a given secret
decrypt decrypt(secret string, msg string) string aes decrypt a message with a given secret
Similar Resources

common tools for golang

utils common tools for golang package main

Dec 27, 2021

redis-util business-friendly encapsulation of redis operations, such as the common cache set get operation

redis-util 方便业务使用的redis操作封装,比如常见的缓存set get操作, 一行代码搞定,不像开源库需要写好多行 使用方法

Oct 22, 2021

Common utils that need in every development

Utils modules Common utils that need in every development Modules Conversion String IntToString(num int) string Int8ToString(num int8) string Int16ToS

Nov 5, 2021

With Pasteback you can store common terms and paste them back to clipboard

Pasteback With Pasteback you can store common terms and paste them back to clipboard when needed. There is one central spot to put every string into y

Nov 22, 2021

Helper functions for common scenarios, using Go generics.

zeroflucs generics When writing Go code for Go 1.17 or below, we've all written more than our fair share of methods to check "does this slice contain

Feb 18, 2022

流媒体NetFlix解锁检测脚本 / A script used to determine whether your network can watch native Netflix movies or not

流媒体NetFlix解锁检测脚本 / A script used to determine whether your network can watch native Netflix movies or not

netflix-verify 流媒体NetFlix解锁检测脚本,使用Go语言编写 在VPS网络正常的情况下,哪怕是双栈网络也可在几秒内快速完成IPv4/IPv6的解锁判断 鸣谢 感谢 @CoiaPrant 指出对于地域检测更简便的方法 感谢 @XmJwit 解决了IPV6 Only VPS无法下载脚

Dec 29, 2022

sigbypass4xx is a utility to automate well-know techniques used to bypass access control restrictions.

sigbypass4xx sigbypass4xx is a utility to automate well-know techniques used to bypass access control restrictions. Resources Usage Installation From

Nov 9, 2022

Package strnaming is used to Convert string to camelCase, snake_case, kebab-case.

strnaming Package strnaming is used to Convert string to camelCase, snake_case, kebab-case. Contents strnaming Contents API Examples Install Quick sta

Oct 24, 2021

MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

Nov 29, 2021
Related tags
Go API backed by the native Dart Sass Embedded executable.

This is a Go API backed by the native Dart Sass Embedded executable. The primary motivation for this project is to provide SCSS support to Hugo. I wel

Jan 5, 2023
squirrelbyte is a "proof of concept" document / search server backed by sqlite.

??️ squirrelbyte is a "proof of concept" document / search server backed by sqlite.

May 20, 2022
Helper library for full uint64 randomness, pool backed for efficient concurrency

fastrand64-go Helper library for full uint64 randomness, pool backed for efficient concurrency Inspired by https://github.com/valyala/fastrand which i

Dec 5, 2021
rxscan provides functionality to scan text to variables using regular expression capture group.

rxscan rxscan provides functionality to scan text to variables using regular expression capture group. This library is still experimental, use at your

Dec 21, 2020
Simple expression evaluation engine for Go

??️ chili Currently in development, Unstable (API may change in future) Simple expression evaluation engine. Expression is one liner that evalutes int

Nov 8, 2022
go expression

golang 实现的表达式计算 功能清单 四则运算 +-*/ 实现; 逻辑运算 and or && || 实现; 参数传递; 逻辑运算符 > >= < <= ! 实现; 自定义方法注入; TODO 优雅的错误返回; 自定义方法注入; 使用 go get -u github.com/huangxing

Sep 29, 2021
This is an open source project for commonly used functions for the Go programming language.

Common Functions This is an open source project for commonly used functions for the Go programming language. This package need >= go 1.3 Code Conventi

Jan 8, 2023
sigurls is a reconnaissance tool, it fetches URLs from AlienVault's OTX, Common Crawl, URLScan, Github and the Wayback Machine.

sigurls is a reconnaissance tool, it fetches URLs from AlienVault's OTX, Common Crawl, URLScan, Github and the Wayback Machine. DiSCLAIMER: fe

May 22, 2021
Use Golang to implement PHP's common built-in functions.

PHP2Go Use Golang to implement PHP's common built-in functions. About 140+ functions have been implemented. Install go get github.com/syyongx/php2go R

Dec 28, 2022
The one-stop shop for most common Go functions
The one-stop shop for most common Go functions

Pandati The one stop shop for most common Go functions Table of contents Pandati The one stop shop for most common Go functions Table of contents Purp

Mar 21, 2022