func (v *Value) GT(other *Value) (bool, error) {
	switch v.Type {
	case "bool":
		v1, v2, err := parseBoolValues(v, other)
		if err != nil {
			return false, err
		}
		if !v1 {
			return false, nil
		}
		if v2 {
			return false, nil
		}
		return true, nil
	case "string":
		if v.Data <= other.Data {
			return false, nil
		}
		return true, nil
	case "int64":
		v1, v2, err := parseInt64Values(v, other)
		if err != nil {
			return false, err
		}
		if v1 <= v2 {
			return false, nil
		}
		return true, nil
	case "float64":
		v1, v2, err := parseFloat64Values(v, other)
		if err != nil {
			return false, err
		}
		if v1 <= v2 {
			return false, nil
		}
		return true, nil
	}
	return false, fmt.Errorf("unknown Value type: %s", v.Type)
}
GT reports whether v is greater than other.
package rule
import (
	"errors"
	"fmt"
	"go/token"
	"strconv"
	"hash/fnv"
)
type Expr interface {
	Eval(Params) (*Value, error)
}
type Params interface {
	GetString(key string) (string, error)
	GetBool(key string) (bool, error)
	GetInt64(key string) (int64, error)
	GetFloat64(key string) (float64, error)
	Keys() []string
	EncodeValue(key string) (string, error)
}
type exprNot struct {
	operator
}
func Not(e Expr) Expr {
	return &exprNot{
		operator: operator{
			kind:     "not",
			operands: []Expr{e},
		},
	}
}
func (n *exprNot) Eval(params Params) (*Value, error) {
	if len(n.operands) < 1 {
		return nil, errors.New("invalid number of operands in Not func")
	}
	op := n.operands[0]
	v, err := op.Eval(params)
	if err != nil {
		return nil, err
	}
	if v.Type != "bool" {
		return nil, errors.New("invalid operand type for Not func")
	}
	if v.Equal(BoolValue(true)) {
		return BoolValue(false), nil
	}
	return BoolValue(true), nil
}
type exprOr struct {
	operator
}
func Or(v1, v2 Expr, vN ...Expr) Expr {
	return &exprOr{
		operator: operator{
			kind:     "or",
			operands: append([]Expr{v1, v2}, vN...),
		},
	}
}
func (n *exprOr) Eval(params Params) (*Value, error) {
	if len(n.operands) < 2 {
		return nil, errors.New("invalid number of operands in Or func")
	}
	opA := n.operands[0]
	vA, err := opA.Eval(params)
	if err != nil {
		return nil, err
	}
	if vA.Type != "bool" {
		return nil, errors.New("invalid operand type for Or func")
	}
	if vA.Equal(BoolValue(true)) {
		return vA, nil
	}
	for i := 1; i < len(n.operands); i++ {
		vB, err := n.operands[i].Eval(params)
		if err != nil {
			return nil, err
		}
		if vB.Type != "bool" {
			return nil, errors.New("invalid operand type for Or func")
		}
		if vB.Equal(BoolValue(true)) {
			return vB, nil
		}
	}
	return BoolValue(false), nil
}
type exprAnd struct {
	operator
}
func And(v1, v2 Expr, vN ...Expr) Expr {
	return &exprAnd{
		operator: operator{
			kind:     "and",
			operands: append([]Expr{v1, v2}, vN...),
		},
	}
}
func (n *exprAnd) Eval(params Params) (*Value, error) {
	if len(n.operands) < 2 {
		return nil, errors.New("invalid number of operands in And func")
	}
	opA := n.operands[0]
	vA, err := opA.Eval(params)
	if err != nil {
		return nil, err
	}
	if vA.Type != "bool" {
		return nil, errors.New("invalid operand type for And func")
	}
	if vA.Equal(BoolValue(false)) {
		return vA, nil
	}
	for i := 1; i < len(n.operands); i++ {
		vB, err := n.operands[i].Eval(params)
		if err != nil {
			return nil, err
		}
		if vB.Type != "bool" {
			return nil, errors.New("invalid operand type for And func")
		}
		if vB.Equal(BoolValue(false)) {
			return vB, nil
		}
	}
	return BoolValue(true), nil
}
type exprEq struct {
	operator
}
func Eq(v1, v2 Expr, vN ...Expr) Expr {
	return &exprEq{
		operator: operator{
			kind:     "eq",
			operands: append([]Expr{v1, v2}, vN...),
		},
	}
}
func (n *exprEq) Eval(params Params) (*Value, error) {
	if len(n.operands) < 2 {
		return nil, errors.New("invalid number of operands in Eq func")
	}
	opA := n.operands[0]
	vA, err := opA.Eval(params)
	if err != nil {
		return nil, err
	}
	for i := 1; i < len(n.operands); i++ {
		vB, err := n.operands[i].Eval(params)
		if err != nil {
			return nil, err
		}
		if !vA.Equal(vB) {
			return BoolValue(false), nil
		}
	}
	return BoolValue(true), nil
}
type exprIn struct {
	operator
}
func In(v, e1 Expr, eN ...Expr) Expr {
	return &exprIn{
		operator: operator{
			kind:     "in",
			operands: append([]Expr{v, e1}, eN...),
		},
	}
}
func (n *exprIn) Eval(params Params) (*Value, error) {
	if len(n.operands) < 2 {
		return nil, errors.New("invalid number of operands in In func")
	}
	toFind := n.operands[0]
	vA, err := toFind.Eval(params)
	if err != nil {
		return nil, err
	}
	for i := 1; i < len(n.operands); i++ {
		vB, err := n.operands[i].Eval(params)
		if err != nil {
			return nil, err
		}
		if vA.Equal(vB) {
			return BoolValue(true), nil
		}
	}
	return BoolValue(false), nil
}
type exprGT struct {
	operator
}
func GT(v1, v2 Expr, vN ...Expr) Expr {
	return &exprGT{
		operator: operator{
			kind:     "gt",
			operands: append([]Expr{v1, v2}, vN...),
		},
	}
}
func (n *exprGT) Eval(params Params) (*Value, error) {
	if len(n.operands) < 2 {
		return nil, errors.New("invalid number of operands in GT func")
	}
	vA, err := n.operands[0].Eval(params)
	if err != nil {
		return nil, err
	}
	for i := 1; i < len(n.operands); i++ {
		vB, err := n.operands[i].Eval(params)
		if err != nil {
			return nil, err
		}
		res, err := vA.GT(vB)
		if err != nil {
			return nil, err
		}
		if !res {
			return BoolValue(false), nil
		}
	}
	return BoolValue(true), nil
}
type exprGTE struct {
	operator
}
func GTE(v1, v2 Expr, vN ...Expr) Expr {
	return &exprGTE{
		operator: operator{
			kind:     "gte",
			operands: append([]Expr{v1, v2}, vN...),
		},
	}
}
func (n *exprGTE) Eval(params Params) (*Value, error) {
	if len(n.operands) < 2 {
		return nil, errors.New("invalid number of operands in GTE func")
	}
	vA, err := n.operands[0].Eval(params)
	if err != nil {
		return nil, err
	}
	for i := 1; i < len(n.operands); i++ {
		vB, err := n.operands[i].Eval(params)
		if err != nil {
			return nil, err
		}
		res, err := vA.GTE(vB)
		if err != nil {
			return nil, err
		}
		if !res {
			return BoolValue(false), nil
		}
	}
	return BoolValue(true), nil
}
type exprLT struct {
	operator
}
func LT(v1, v2 Expr, vN ...Expr) Expr {
	return &exprLT{
		operator: operator{
			kind:     "lt",
			operands: append([]Expr{v1, v2}, vN...),
		},
	}
}
func (n *exprLT) Eval(params Params) (*Value, error) {
	if len(n.operands) < 2 {
		return nil, errors.New("invalid number of operands in LT func")
	}
	vA, err := n.operands[0].Eval(params)
	if err != nil {
		return nil, err
	}
	for i := 1; i < len(n.operands); i++ {
		vB, err := n.operands[i].Eval(params)
		if err != nil {
			return nil, err
		}
		res, err := vA.LT(vB)
		if err != nil {
			return nil, err
		}
		if !res {
			return BoolValue(false), nil
		}
	}
	return BoolValue(true), nil
}
type exprLTE struct {
	operator
}
func LTE(v1, v2 Expr, vN ...Expr) Expr {
	return &exprLTE{
		operator: operator{
			kind:     "lte",
			operands: append([]Expr{v1, v2}, vN...),
		},
	}
}
func (n *exprLTE) Eval(params Params) (*Value, error) {
	if len(n.operands) < 2 {
		return nil, errors.New("invalid number of operands in LTE func")
	}
	vA, err := n.operands[0].Eval(params)
	if err != nil {
		return nil, err
	}
	for i := 1; i < len(n.operands); i++ {
		vB, err := n.operands[i].Eval(params)
		if err != nil {
			return nil, err
		}
		res, err := vA.LTE(vB)
		if err != nil {
			return nil, err
		}
		if !res {
			return BoolValue(false), nil
		}
	}
	return BoolValue(true), nil
}
type exprFNV struct {
	operator
}
func FNV(v Expr) Expr {
	return &exprFNV{
		operator: operator{
			kind:     "fnv",
			operands: []Expr{v},
		},
	}
}
func (n *exprFNV) Eval(params Params) (*Value, error) {
	if len(n.operands) != 1 {
		return nil, errors.New("invalid number of operands in FNV func")
	}
	h32 := fnv.New32()
	op := n.operands[0]
	v, err := op.Eval(params)
	if err != nil {
		return nil, err
	}
	_, err = h32.Write([]byte(v.Data))
	if err != nil {
		return nil, err
	}
	return Int64Value(int64(h32.Sum32())), nil
}
type exprPercentile struct {
	operator
}
func Percentile(v, p Expr) Expr {
	return &exprPercentile{
		operator: operator{
			kind:     "percentile",
			operands: []Expr{v, p},
		},
	}
}
func (n *exprPercentile) Eval(params Params) (*Value, error) {
	if len(n.operands) != 2 {
		return nil, errors.New("invalid number of operands in Percentile func")
	}
	hash := FNV(n.operands[0])
	v, err := exprToInt64(hash, params)
	if err != nil {
		return nil, err
	}
	p, err := exprToInt64(n.operands[1], params)
	if err != nil {
		return nil, err
	}
	if (v % 100) <= p {
		return BoolValue(true), nil
	}
	return BoolValue(false), nil
}
type Param struct {
	Kind string `json:"kind"`
	Type string `json:"type"`
	Name string `json:"name"`
}
func StringParam(name string) *Param {
	return &Param{
		Kind: "param",
		Type: "string",
		Name: name,
	}
}
func BoolParam(name string) *Param {
	return &Param{
		Kind: "param",
		Type: "bool",
		Name: name,
	}
}
func Int64Param(name string) *Param {
	return &Param{
		Kind: "param",
		Type: "int64",
		Name: name,
	}
}
func Float64Param(name string) *Param {
	return &Param{
		Kind: "param",
		Type: "float64",
		Name: name,
	}
}
func (p *Param) Eval(params Params) (*Value, error) {
	if params == nil {
		return nil, errors.New("params is nil")
	}
	switch p.Type {
	case "string":
		v, err := params.GetString(p.Name)
		if err != nil {
			return nil, err
		}
		return StringValue(v), nil
	case "bool":
		v, err := params.GetBool(p.Name)
		if err != nil {
			return nil, err
		}
		return BoolValue(v), nil
	case "int64":
		v, err := params.GetInt64(p.Name)
		if err != nil {
			return nil, err
		}
		return Int64Value(v), nil
	case "float64":
		v, err := params.GetFloat64(p.Name)
		if err != nil {
			return nil, err
		}
		return Float64Value(v), nil
	}
	return nil, errors.New("unsupported param type")
}
func True() Expr {
	return BoolValue(true)
}
type Value struct {
	Kind string `json:"kind"`
	Type string `json:"type"`
	Data string `json:"data"`
}
func newValue(typ, data string) *Value {
	return &Value{
		Kind: "value",
		Type: typ,
		Data: data,
	}
}
func BoolValue(value bool) *Value {
	return newValue("bool", strconv.FormatBool(value))
}
func StringValue(value string) *Value {
	return newValue("string", value)
}
func Int64Value(value int64) *Value {
	return newValue("int64", strconv.FormatInt(value, 10))
}
func Float64Value(value float64) *Value {
	return newValue("float64", strconv.FormatFloat(value, 'f', 6, 64))
}
func (v *Value) Eval(Params) (*Value, error) {
	return v, nil
}
func (v *Value) compare(op token.Token, other *Value) bool {
	if op != token.EQL {
		return false
	}
	return *v == *other
}
func (v *Value) Equal(other *Value) bool {
	return v.compare(token.EQL, other)
}