Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
linxiaozhi committed Dec 21, 2023
1 parent 42b8ab6 commit bfe7b2b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cli/file_config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type fileConfigUpdate interface {
}

func NewFileConfigHandler(notifier fileConfigUpdate, logger core.Logger) (*FileConfigHandler, error) {
logger.Debugf("FileConfigHandler NewFileConfigHandler")

c := &FileConfigHandler{}
c.notifier = notifier
c.logger = logger
Expand All @@ -28,13 +30,14 @@ func NewFileConfigHandler(notifier fileConfigUpdate, logger core.Logger) (*FileC
}

func (c *FileConfigHandler) watch() {
cfgHash := getCfgHash(c.ConfigFile)
cfgHash := c.getCfgHash(c.ConfigFile)
c.logger.Debugf("FileConfigHandler watch")

tick := time.Tick(10000 * time.Millisecond)
for {
select {
case <-tick:
newCfgHash := getCfgHash(c.ConfigFile)
newCfgHash := c.getCfgHash(c.ConfigFile)
c.logger.Debugf("config file hash,old hash:%s,new hash:%s", cfgHash, newCfgHash)
if cfgHash != newCfgHash {
c.logger.Debugf("config file has changed,old hash:%s,new hash:%s", cfgHash, newCfgHash)
Expand All @@ -49,16 +52,16 @@ func (c *FileConfigHandler) watch() {
}
}

func getCfgHash(filename string) string {
func (c *FileConfigHandler) getCfgHash(filename string) string {
file, err := os.Open(filename)
defer file.Close()
if err != nil {
panic(err)
c.logger.Errorf(err.Error())
}

hash := sha256.New()
if _, err := io.Copy(hash, file); err != nil {
panic(err)
c.logger.Errorf(err.Error())
}
sum := fmt.Sprintf("%x", hash.Sum(nil))

Expand Down

0 comments on commit bfe7b2b

Please sign in to comment.