-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
options.go
67 lines (56 loc) · 1.83 KB
/
options.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
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
package strftime
type Option interface {
Name() string
Value() interface{}
}
type option struct {
name string
value interface{}
}
func (o *option) Name() string { return o.name }
func (o *option) Value() interface{} { return o.value }
const optSpecificationSet = `opt-specification-set`
// WithSpecification allows you to specify a custom specification set
func WithSpecificationSet(ds SpecificationSet) Option {
return &option{
name: optSpecificationSet,
value: ds,
}
}
type optSpecificationPair struct {
name byte
appender Appender
}
const optSpecification = `opt-specification`
// WithSpecification allows you to create a new specification set on the fly,
// to be used only for that invocation.
func WithSpecification(b byte, a Appender) Option {
return &option{
name: optSpecification,
value: &optSpecificationPair{
name: b,
appender: a,
},
}
}
// WithMilliseconds is similar to WithSpecification, and specifies that
// the Strftime object should interpret the pattern `%b` (where b
// is the byte that you specify as the argument)
// as the zero-padded, 3 letter milliseconds of the time.
func WithMilliseconds(b byte) Option {
return WithSpecification(b, Milliseconds())
}
// WithMicroseconds is similar to WithSpecification, and specifies that
// the Strftime object should interpret the pattern `%b` (where b
// is the byte that you specify as the argument)
// as the zero-padded, 3 letter microseconds of the time.
func WithMicroseconds(b byte) Option {
return WithSpecification(b, Microseconds())
}
// WithUnixSeconds is similar to WithSpecification, and specifies that
// the Strftime object should interpret the pattern `%b` (where b
// is the byte that you specify as the argument)
// as the unix timestamp in seconds
func WithUnixSeconds(b byte) Option {
return WithSpecification(b, UnixSeconds())
}