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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?