go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/selector/not_has_key.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package selector
     9  
    10  import "fmt"
    11  
    12  // NotHasKey returns if a label set does not have a given key.
    13  type NotHasKey string
    14  
    15  // Matches returns the selector result.
    16  func (nhk NotHasKey) Matches(labels Labels) bool {
    17  	if _, hasKey := labels[string(nhk)]; hasKey {
    18  		return false
    19  	}
    20  	return true
    21  }
    22  
    23  // Validate validates the selector.
    24  func (nhk NotHasKey) Validate() (err error) {
    25  	err = CheckKey(string(nhk))
    26  	return
    27  }
    28  
    29  // String returns a string representation of the selector.
    30  func (nhk NotHasKey) String() string {
    31  	return fmt.Sprintf("!%s", string(nhk))
    32  }