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