go-resty-expr

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2022 License: Apache-2.0

README

go-resty-expr

GitHub top language GitHub Action GitHub visitors

go-resty-expr is a toolkit for creating golang struct by expressions from lua-resty-expr


It includes an expression syntax to avoid use nest interface{} create json like array.

package main

import (
	"encoding/json"
	"fmt"
	"github.com/incubator4/go-resty-expr/expr"
)

func main() {
	var exprs = expr.And(
		expr.StringExpr("arg_name").Equals(expr.StringExpr("json")),
		expr.Or(
			expr.StringExpr("arg_weight").GreaterThan(expr.NumberExpr(10)),
			expr.StringExpr("arg_height").Not().GreaterThan(expr.NumberExpr(15)),
		),
	).ToArray()

	bytedata, err := json.Marshal(exprs)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(bytedata))
	// ["AND",["arg_name","==","json"],["OR",["arg_weight","\u003e",10],["arg_height","!","\u003e",15]]]
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL