wildcard.go 1015 B

12345678910111213141516171819202122232425262728293031323334353637
  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. package path
  5. import "notabug.org/themusicgod1/goarista/key"
  6. // Wildcard is a special element in a path that is used by Map
  7. // and the Match* functions to match any other element.
  8. var Wildcard = key.New(WildcardType{})
  9. // WildcardType is the type used to construct a Wildcard. It
  10. // implements the value.Value interface so it can be used as
  11. // a key.Key.
  12. type WildcardType struct{}
  13. func (w WildcardType) String() string {
  14. return "*"
  15. }
  16. // Equal implements the key.Comparable interface.
  17. func (w WildcardType) Equal(other interface{}) bool {
  18. _, ok := other.(WildcardType)
  19. return ok
  20. }
  21. // ToBuiltin implements the value.Value interface.
  22. func (w WildcardType) ToBuiltin() interface{} {
  23. return WildcardType{}
  24. }
  25. // MarshalJSON implements the value.Value interface.
  26. func (w WildcardType) MarshalJSON() ([]byte, error) {
  27. return []byte(`{"_wildcard":{}}`), nil
  28. }