feat: add logrotate settings validation and testing

This commit is contained in:
0xJacky
2026-03-14 22:04:43 +08:00
parent 029142f944
commit a6491e437f
4 changed files with 116 additions and 6 deletions

View File

@@ -1,13 +1,33 @@
package settings
import "time"
const (
defaultLogrotateIntervalMinutes = 1440
)
const InvalidLogrotateIntervalMessage = "logrotate interval must be greater than 0"
type Logrotate struct {
Enabled bool `json:"enabled"`
CMD string `json:"cmd" protected:"true"`
Interval int `json:"interval"`
Interval int `json:"interval" binding:"omitempty,min=1"`
}
var LogrotateSettings = &Logrotate{
Enabled: false,
CMD: "logrotate /etc/logrotate.d/nginx",
Interval: 1440, // 24 hours
Interval: defaultLogrotateIntervalMinutes, // 24 hours
}
func (l Logrotate) HasValidInterval() bool {
return l.Interval > 0
}
func (l Logrotate) GetInterval() time.Duration {
if !l.HasValidInterval() {
return defaultLogrotateIntervalMinutes * time.Minute
}
return time.Duration(l.Interval) * time.Minute
}