github.com/tomwright/dasel@v1.27.3/condition_key_equal.go (about)

     1  package dasel
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  )
     7  
     8  // KeyEqualCondition lets you check for an exact match.
     9  type KeyEqualCondition struct {
    10  	// Value is the value we are looking for.
    11  	Value string
    12  	// Not is true if this is a not equal check.
    13  	Not bool
    14  }
    15  
    16  func (c KeyEqualCondition) check(a interface{}, b interface{}) (bool, error) {
    17  	var res = fmt.Sprint(a) == b
    18  	if c.Not {
    19  		res = !res
    20  	}
    21  	return res, nil
    22  }
    23  
    24  // Check checks to see if other contains the required key value pair.
    25  func (c KeyEqualCondition) Check(other reflect.Value) (bool, error) {
    26  	if !other.IsValid() {
    27  		return false, &UnhandledCheckType{Value: nil}
    28  	}
    29  
    30  	value := unwrapValue(other)
    31  
    32  	return c.check(c.Value, value.String())
    33  }