From 6634aa675ecb69e44851966561f8f4b6f3be01ad Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Wed, 5 Jul 2023 21:29:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=90=8E=E6=97=A0=E9=99=90=E5=88=B7=E6=96=B0=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.go | 26 ++++++++++++------------- planner/configexport/internal/config.go | 4 ++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/config/config.go b/config/config.go index 47c9494..a212b34 100644 --- a/config/config.go +++ b/config/config.go @@ -29,6 +29,7 @@ var ( cRefreshHandle RefreshHandle json = jsonIter.ConfigCompatibleWithStandardLibrary mutex sync.Mutex + isInit = true ) // Init 配置初始化 @@ -44,24 +45,23 @@ func Init(loadDir string, loadHandle LoadHandle, refreshHandle RefreshHandle) { // - 加载后并不会刷新线上配置,需要执行 Refresh 函数对线上配置进行刷新 func Load() { mutex.Lock() - if cTicker != nil { - WithTickerLoad(cTicker, cInterval) - } else { - cLoadHandle(func(filename string, config any) error { - bytes, err := os.ReadFile(filepath.Join(cLoadDir, filename)) - if err != nil { - return err - } - if err = json.Unmarshal(bytes, &config); err == nil { - log.Info("Config", zap.String("Name", filename), zap.Bool("LoadSuccess", true)) - } + cLoadHandle(func(filename string, config any) error { + bytes, err := os.ReadFile(filepath.Join(cLoadDir, filename)) + if err != nil { return err - }) - } + } + if err = json.Unmarshal(bytes, &config); err == nil && isInit { + log.Info("Config", zap.String("Name", filename), zap.Bool("LoadSuccess", true)) + } + return err + }) + isInit = false mutex.Unlock() } // WithTickerLoad 通过定时器加载配置 +// - 通过定时器加载配置后,会自动刷新线上配置 +// - 调用该函数后将会立即加载并刷新一次配置,随后每隔 interval 时间加载并刷新一次配置 func WithTickerLoad(ticker *timer.Ticker, interval time.Duration) { if ticker != cTicker && cTicker != nil { cTicker.StopTimer(tickerLoadRefresh) diff --git a/planner/configexport/internal/config.go b/planner/configexport/internal/config.go index 17d7cc1..4dd81d5 100644 --- a/planner/configexport/internal/config.go +++ b/planner/configexport/internal/config.go @@ -264,6 +264,10 @@ func (slf *Config) initData() error { if slf.horizontal { c := slf.matrix.Get(x+i, y) if c == nil { + if currentIndex < slf.IndexCount { + stop = true + break + } value = getValueZero(field.SourceType) zero = true } else if currentIndex < slf.IndexCount && len(strings.TrimSpace(c.String())) == 0 {