github.com/blend/go-sdk@v1.20220411.3/selector/equals.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package selector
     9  
    10  import "fmt"
    11  
    12  // Equals returns if a key strictly equals a value.
    13  type Equals struct {
    14  	Key, Value string
    15  }
    16  
    17  // Matches returns the selector result.
    18  func (e Equals) Matches(labels Labels) bool {
    19  	if value, hasValue := labels[e.Key]; hasValue {
    20  		return e.Value == value
    21  	}
    22  	return false
    23  }
    24  
    25  // Validate validates the selector.
    26  func (e Equals) Validate() (err error) {
    27  	err = CheckKey(e.Key)
    28  	if err != nil {
    29  		return
    30  	}
    31  	err = CheckValue(e.Value)
    32  	return
    33  }
    34  
    35  // String returns the string representation of the selector.
    36  func (e Equals) String() string {
    37  	return fmt.Sprintf("%s == %s", e.Key, e.Value)
    38  }