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