fix: concurrency protect configuing
continuous-integration/drone/tag Build is passing Details

feat/muzan v0.1.8
Evan Chen 2021-11-05 11:10:13 +08:00
parent f76cc2f75e
commit 8b85b8e89b
1 changed files with 12 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import (
"fmt"
"html/template"
"os"
"sync"
"time"
"kumoly.io/lib/klog"
@ -17,7 +18,7 @@ import (
var UNIX_SHELL = "sh"
var WIN_SHELL = "cmd"
const version = "v0.1.3"
const version = "v0.1.8"
//go:embed templates
var tmplFS embed.FS
@ -52,12 +53,13 @@ type ConfigUI struct {
LogPath string `json:"log_path"`
LogLevel int `json:"log_level"`
TmplFS embed.FS `json:"-"`
tmpl *engine.Engine
PublicFS embed.FS `json:"-"`
log *klog.Logger `json:"-"`
ksrv_log *klog.Logger `json:"-"`
f *os.File `json:"-"`
TmplFS embed.FS `json:"-"`
tmpl *engine.Engine
PublicFS embed.FS `json:"-"`
log *klog.Logger `json:"-"`
ksrv_log *klog.Logger `json:"-"`
f *os.File `json:"-"`
configLock sync.Mutex `json:"-"`
}
func New() *ConfigUI {
@ -119,6 +121,8 @@ func (cui *ConfigUI) LoadConfig(confstr string) error {
}
// copy
cui.configLock.Lock()
defer cui.configLock.Unlock()
cui.fileIndex = tmpIndex
cui.Files = tmpConf.Files
cui.AllowIP = tmpConf.AllowIP
@ -127,6 +131,7 @@ func (cui *ConfigUI) LoadConfig(confstr string) error {
cui.ConfigPath = tmpConf.ConfigPath
cui.HideConfig = tmpConf.HideConfig
cui.NoReconfig = tmpConf.NoReconfig
cui.ResultBellow = tmpConf.ResultBellow
cui.AppName = tmpConf.AppName
if cui.AppName == "" {
@ -149,9 +154,6 @@ func (cui *ConfigUI) LoadConfig(confstr string) error {
cui.log = klog.Sub(cui.AppName)
// NOT implemented
cui.ResultBellow = tmpConf.ResultBellow
cui.LogLevel = tmpConf.LogLevel
if cui.LogLevel == 0 {
cui.LogLevel = klog.Lerror | klog.Linfo