/
versioner.go
40 lines (32 loc) · 1.02 KB
/
versioner.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
package backups
import (
"time"
)
// Versioner provides methods for generating version strings for backups.
type Versioner interface {
GetVersion() string
}
// TimestampVersioner is a Versioner that returns a timestamp that can be used to
// version a file. It takes a `time.Time` which it uses to create the version.
type TimestampVersioner struct {
}
// NewTimestampVersioner returns a new TimestampVersioner for the given time.
func NewTimestampVersioner() TimestampVersioner {
return TimestampVersioner{}
}
// GetVersion returns a filename-safe version string in the format `YmdTHMS`.
//
// For example, if the versioner was created on August 15, 2019 at 15:00:00, the
// version string would look like `20190815T150000`.
func (v TimestampVersioner) GetVersion() string {
return time.Now().Format("20060102T150405")
}
type staticVersioner struct {
version string
}
func newStaticVersioner(version string) staticVersioner {
return staticVersioner{version}
}
func (v staticVersioner) GetVersion() string {
return v.version
}