feat(cmd/joj3/conf): support effective time
This commit is contained in:
parent
575a3ae042
commit
b3663d8782
|
@ -173,10 +173,15 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) (
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckExpire(conf *Conf) error {
|
func CheckValid(conf *Conf) error {
|
||||||
|
now := time.Now().Unix()
|
||||||
|
if conf.EffectiveUnixTimestamp > 0 &&
|
||||||
|
conf.EffectiveUnixTimestamp > now {
|
||||||
|
return fmt.Errorf("config file not effective now: %d", now)
|
||||||
|
}
|
||||||
if conf.ExpireUnixTimestamp > 0 &&
|
if conf.ExpireUnixTimestamp > 0 &&
|
||||||
conf.ExpireUnixTimestamp < time.Now().Unix() {
|
conf.ExpireUnixTimestamp < now {
|
||||||
return fmt.Errorf("config file expired: %d", conf.ExpireUnixTimestamp)
|
return fmt.Errorf("config file expired now: %d", now)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,16 +20,11 @@ type ConfStage struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfGroup struct {
|
|
||||||
Name string
|
|
||||||
MaxCount int
|
|
||||||
TimePeriodHour int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
Name string `default:"unknown"`
|
Name string `default:"unknown"`
|
||||||
LogPath string `default:""`
|
LogPath string `default:""`
|
||||||
ActorCsvPath string `default:""`
|
ActorCsvPath string `default:""`
|
||||||
|
EffectiveUnixTimestamp int64 `default:"-1"`
|
||||||
ExpireUnixTimestamp int64 `default:"-1"`
|
ExpireUnixTimestamp int64 `default:"-1"`
|
||||||
MaxTotalScore int `default:"-1"`
|
MaxTotalScore int `default:"-1"`
|
||||||
Stage struct {
|
Stage struct {
|
||||||
|
|
|
@ -83,8 +83,8 @@ func mainImpl() (err error) {
|
||||||
}
|
}
|
||||||
slog.Info("conf info", "sha256", confSHA256, "modTime", confStat.ModTime(),
|
slog.Info("conf info", "sha256", confSHA256, "modTime", confStat.ModTime(),
|
||||||
"size", confStat.Size())
|
"size", confStat.Size())
|
||||||
if err := joj3Conf.CheckExpire(conf); err != nil {
|
if err := joj3Conf.CheckValid(conf); err != nil {
|
||||||
slog.Error("conf check expire", "error", err)
|
slog.Error("conf not valid now", "error", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user