forked from influxdata/go-syslog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
year.go
38 lines (30 loc) · 868 Bytes
/
year.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
package rfc3164
import (
"time"
)
// YearOperator is an interface that the operation inferring the year have to implement.
type YearOperator interface {
Apply() int
}
// YearOperation represents the operation to perform to obtain the year depending on the inner operator/strategy.
type YearOperation struct {
Operator YearOperator
}
// Operate gets the year depending on the current strategy.
func (y YearOperation) Operate() int {
return y.Operator.Apply()
}
// CurrentYear is a strategy to obtain the current year in RFC 3164 syslog messages.
type CurrentYear struct{}
// Apply gets the current year
func (CurrentYear) Apply() int {
return time.Now().Year()
}
// Year is a strategy to obtain the specified year in the RFC 3164 syslog messages.
type Year struct {
YYYY int
}
// Apply gets the specified year
func (y Year) Apply() int {
return y.YYYY
}