added functionality HardCacheDuration to config.ini
This commit is contained in:
parent
49f613ddeb
commit
8fe6783ecb
7 changed files with 52 additions and 73 deletions
41
config.go
41
config.go
|
@ -2,14 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
|
@ -158,44 +155,8 @@ func loadConfig() Config {
|
|||
WebsiteEnabled: websiteEnabled,
|
||||
LogLevel: logLevel,
|
||||
HardCacheDuration: hardCacheDuration,
|
||||
HardCacheEnabled: hardCacheDuration != 0,
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
var configLock sync.RWMutex
|
||||
|
||||
func startFileWatcher() {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
printErr("%v", err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer watcher.Close()
|
||||
for {
|
||||
select {
|
||||
case event, ok := <-watcher.Events:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if event.Op&fsnotify.Write == fsnotify.Write {
|
||||
printInfo("Modified file: %v", event.Name)
|
||||
configLock.Lock()
|
||||
config = loadConfig()
|
||||
configLock.Unlock()
|
||||
}
|
||||
case err, ok := <-watcher.Errors:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
printWarn("Error watching configuration file: %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = watcher.Add(configFilePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue