github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/path/wildcard.go (about) 1 // Copyright (c) 2018 Arista Networks, Inc. 2 // Use of this source code is governed by the Apache License 2.0 3 // that can be found in the COPYING file. 4 5 package path 6 7 import "github.com/aristanetworks/goarista/key" 8 9 // Wildcard is a special element in a path that is used by Map 10 // and the Match* functions to match any other element. 11 var Wildcard = key.New(WildcardType{}) 12 13 // WildcardType is the type used to construct a Wildcard. It 14 // implements the value.Value interface so it can be used as 15 // a key.Key. 16 type WildcardType struct{} 17 18 func (w WildcardType) String() string { 19 return "*" 20 } 21 22 // Equal implements the key.Comparable interface. 23 func (w WildcardType) Equal(other interface{}) bool { 24 _, ok := other.(WildcardType) 25 return ok 26 } 27 28 // ToBuiltin implements the value.Value interface. 29 func (w WildcardType) ToBuiltin() interface{} { 30 return WildcardType{} 31 } 32 33 // MarshalJSON implements the value.Value interface. 34 func (w WildcardType) MarshalJSON() ([]byte, error) { 35 return []byte(`{"_wildcard":{}}`), nil 36 }