chore: refactoring (#2182)

master
Kevin Wan 2 years ago committed by GitHub
parent 34eb3fc12e
commit 92145b56dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,8 +19,8 @@ import (
) )
const ( const (
rfc3339DateFormat = time.RFC3339
dateFormat = "2006-01-02" dateFormat = "2006-01-02"
fileTimeFormat = time.RFC3339
hoursPerDay = 24 hoursPerDay = 24
bufferSize = 100 bufferSize = 100
defaultDirMode = 0o755 defaultDirMode = 0o755
@ -195,7 +195,7 @@ func (r *SizeLimitRotateRule) OutdatedFiles() []string {
// test if any too old backups // test if any too old backups
if r.days > 0 { if r.days > 0 {
boundary := time.Now().Add(-time.Hour * time.Duration(hoursPerDay*r.days)).Format(rfc3339DateFormat) boundary := time.Now().Add(-time.Hour * time.Duration(hoursPerDay*r.days)).Format(fileTimeFormat)
boundaryFile := filepath.Join(dir, fmt.Sprintf("%s%s%s%s", prefix, r.delimiter, boundary, ext)) boundaryFile := filepath.Join(dir, fmt.Sprintf("%s%s%s%s", prefix, r.delimiter, boundary, ext))
if r.gzip { if r.gzip {
boundaryFile += gzipExt boundaryFile += gzipExt
@ -413,7 +413,7 @@ func getNowDate() string {
} }
func getNowDateInRFC3339Format() string { func getNowDateInRFC3339Format() string {
return time.Now().Format(rfc3339DateFormat) return time.Now().Format(fileTimeFormat)
} }
func gzipFile(file string) error { func gzipFile(file string) error {

@ -51,7 +51,7 @@ func TestSizeLimitRotateRuleOutdatedFiles(t *testing.T) {
func TestSizeLimitRotateRuleShallRotate(t *testing.T) { func TestSizeLimitRotateRuleShallRotate(t *testing.T) {
var rule SizeLimitRotateRule var rule SizeLimitRotateRule
rule.rotatedTime = time.Now().Add(time.Hour * 24).Format(rfc3339DateFormat) rule.rotatedTime = time.Now().Add(time.Hour * 24).Format(fileTimeFormat)
rule.maxSize = 0 rule.maxSize = 0
assert.False(t, rule.ShallRotate(0)) assert.False(t, rule.ShallRotate(0))
rule.maxSize = 100 rule.maxSize = 100

@ -41,12 +41,12 @@ type keepAliveServer struct {
Server Server
} }
func (ags keepAliveServer) Start(fn RegisterFn) error { func (s keepAliveServer) Start(fn RegisterFn) error {
if err := ags.registerEtcd(); err != nil { if err := s.registerEtcd(); err != nil {
return err return err
} }
return ags.Server.Start(fn) return s.Server.Start(fn)
} }
func figureOutListenOn(listenOn string) string { func figureOutListenOn(listenOn string) string {

Loading…
Cancel
Save