-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty.go
More file actions
176 lines (143 loc) · 4.85 KB
/
property.go
File metadata and controls
176 lines (143 loc) · 4.85 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package properties
import (
"context"
"time"
)
// PropertyName is the name of a property
type PropertyName string
// A Property expresses a single front matter variable
type Property interface {
Name(context.Context) PropertyName
AnyValue(context.Context) interface{}
Copy(context.Context, map[string]interface{}, ...interface{})
}
// TextProperty holds a named string
type TextProperty interface {
Property
Value(context.Context) string
}
// TextListProperty holds a named string slice
type TextListProperty interface {
Property
Value(context.Context) []string
}
// FlagProperty holds a named boolean flag
type FlagProperty interface {
Property
Value(context.Context) bool
}
// DateTimeProperty holds a named wall time
type DateTimeProperty interface {
Property
Value(context.Context) time.Time
}
// CardinalProperty holds a named cardinal value
type CardinalProperty interface {
Property
Value(context.Context) int64
}
// DefaultDateTimeProperty implements DateTimeProperty
type DefaultDateTimeProperty struct {
PropName PropertyName `json:"name"`
Time time.Time `json:"value"`
}
// Copy copies the key/value pair into the given map
func (p *DefaultDateTimeProperty) Copy(ctx context.Context, m map[string]interface{}, options ...interface{}) {
m[string(p.PropName)] = p.Time
}
// Name returns the property name
func (p *DefaultDateTimeProperty) Name(context.Context) PropertyName {
return p.PropName
}
// AnyValue returns the property value useful when the type isn't important
func (p *DefaultDateTimeProperty) AnyValue(context.Context) interface{} {
return p.Time
}
// Value returns the property value when the type is important
func (p *DefaultDateTimeProperty) Value(context.Context) time.Time {
return p.Time
}
// DefaultFlagProperty implements FlagProperty
type DefaultFlagProperty struct {
PropName PropertyName `json:"name"`
Flag bool `json:"value"`
}
// Copy copies the key/value pair into the given map
func (p *DefaultFlagProperty) Copy(ctx context.Context, m map[string]interface{}, options ...interface{}) {
m[string(p.PropName)] = p.Flag
}
// Name returns the property name
func (p *DefaultFlagProperty) Name(context.Context) PropertyName {
return p.PropName
}
// AnyValue returns the property value useful when the type isn't important
func (p *DefaultFlagProperty) AnyValue(context.Context) interface{} {
return p.Flag
}
// Value returns the property value when the type is important
func (p *DefaultFlagProperty) Value(context.Context) bool {
return p.Flag
}
// DefaultCardinalProperty implements CardinalProperty
type DefaultCardinalProperty struct {
PropName PropertyName `json:"name"`
Number int64 `json:"value"`
}
// Copy copies the key/value pair into the given map
func (p *DefaultCardinalProperty) Copy(ctx context.Context, m map[string]interface{}, options ...interface{}) {
m[string(p.PropName)] = p.Number
}
// Name returns the property name
func (p *DefaultCardinalProperty) Name(context.Context) PropertyName {
return p.PropName
}
// AnyValue returns the property value useful when the type isn't important
func (p *DefaultCardinalProperty) AnyValue(context.Context) interface{} {
return p.Number
}
// Value returns the property value when the type is important
func (p *DefaultCardinalProperty) Value(context.Context) int64 {
return p.Number
}
// DefaultTextProperty implements TextProperty
type DefaultTextProperty struct {
PropName PropertyName `json:"name"`
Text string `json:"value"`
}
// Copy copies the key/value pair into the given map
func (p *DefaultTextProperty) Copy(ctx context.Context, m map[string]interface{}, options ...interface{}) {
m[string(p.PropName)] = p.Text
}
// Name returns the property name
func (p *DefaultTextProperty) Name(context.Context) PropertyName {
return p.PropName
}
// AnyValue returns the property value useful when the type isn't important
func (p *DefaultTextProperty) AnyValue(context.Context) interface{} {
return p.Text
}
// Value returns the property value when the type is important
func (p *DefaultTextProperty) Value(context.Context) string {
return p.Text
}
// DefaultTextListProperty implements TextListProperty
type DefaultTextListProperty struct {
PropName PropertyName `json:"name"`
Slice []string `json:"value"`
}
// Copy copies the key/value pair into the given map
func (p *DefaultTextListProperty) Copy(ctx context.Context, m map[string]interface{}, options ...interface{}) {
m[string(p.PropName)] = p.Slice
}
// Name returns the property name
func (p *DefaultTextListProperty) Name(context.Context) PropertyName {
return p.PropName
}
// AnyValue returns the property value useful when the type isn't important
func (p *DefaultTextListProperty) AnyValue(context.Context) interface{} {
return p.Slice
}
// Value returns the property value when the type is important
func (p *DefaultTextListProperty) Value(context.Context) []string {
return p.Slice
}