go-ruler

basic rules engine for go

Github星跟踪图

go-ruler

json-y object testing in go

Installation

go get github.com/hopkinsth/go-ruler

Introduction

go-ruler is an implementaion of ruler in go, partly as an experiment, eventually as an optimization strategy. go-ruler supports programmatically constructing rules in a way similar to js-ruler and can also process rules stored in arrays of JSON objects with this structure:

{
  "comparator": "eq",
  "path": "library.name",
  "value": "go-ruler"
}

Each of those objects (or 'filters') describes a condition for a property on some JSON object or json-object-esque structure. (In this go implementation, we're using map[string]interface{}.)

Example

package main

import "github.com/hopkinsth/go-ruler"
import "fmt"

func main() {
  rules := []byte(`[
    {"comparator": "eq", "path": "library.name", "value": "go-ruler"},
    {"comparator": "gt", "path": "library.age", "value": 0.5}
  ]`)

  // supports loading rules from JSON data
  engine, _ := ruler.NewRulerWithJson(rules)

  // can also build rules programmatically
  engine = ruler.NewRuler()
  engine.Rule("library.name").
    Eq("go-ruler").
    End().
  Rule("library.age").
    Gt(0.5)

  result := engine.Test(map[string]interface{}{
    "library": map[string]interface{}{
      "name": "go-ruler",
      "age":  1.24,
    },
  })

  fmt.Println(result == true)
}

License

Copyright 2015 Thomas Hopkins

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

主要指标

概览
名称与所有者hopkinsth/go-ruler
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证Apache License 2.0
所有者活动
创建于2015-06-11 02:09:08
推送于2019-01-03 20:30:06
最后一次提交2015-06-18 21:27:15
发布数0
用户参与
星数118
关注者数7
派生数30
提交数27
已启用问题?
问题数4
打开的问题数3
拉请求数0
打开的拉请求数3
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?