From b9730776abd2fd3122b922a698e5b1c4925ffd7b Mon Sep 17 00:00:00 2001 From: "jackdaw@loafle.com" Date: Wed, 10 May 2017 15:14:31 +0900 Subject: [PATCH] . --- config_manager.go | 12 ++++++++++-- config_manager_test.go | 4 +--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/config_manager.go b/config_manager.go index 8276258..847eb77 100644 --- a/config_manager.go +++ b/config_manager.go @@ -56,6 +56,12 @@ func (c *configManager) getContainerPath() string { return c.getConfigPath() + "container/" } +func (c *configManager) getConfigFilePath(config *config_manager.Config) string { + return c.getContainerPath() + appendSeperator(config.Crawler.Container) + appendSeperator(config.Crawler.Name) + config.Id +} + + + func appendSeperator(str string) string { if strings.LastIndex(str, "/") != len(str)-1 { return str + "/" @@ -100,6 +106,8 @@ func (c *configManager) loadCrawlerConfig(root string, dir string) { } for _, file := range files { + + // 디렉터리라면 재귀 / 파일이라면 설정 로드 if file.IsDir() == true { c.loadCrawlerConfig(currentDir, file.Name()) } else { @@ -135,7 +143,7 @@ func (c *configManager) addConfig() { // agent 폴더 / config / crawler / .. / .. / .. / 에 해당하는 파일이 있는지 확인, 있다면 삭제 // Config 파일로 저장 - savePath := c.getContainerPath() + appendSeperator(m.Crawler.Container) + appendSeperator(m.Crawler.Name) + m.Id + savePath := c.getConfigFilePath(&m) ioutil.WriteFile(savePath, b, 0644) // tempfile remove @@ -167,7 +175,7 @@ func (c *configManager) removeConfig() { } // 해당 파일 삭제 - path := c.getContainerPath() + appendSeperator(config.Crawler.Container) + appendSeperator(config.Crawler.Name) + config.Id + path := c.getConfigFilePath(config) err := os.Remove(path) if err != nil { // error check diff --git a/config_manager_test.go b/config_manager_test.go index f432ba3..e2c37f1 100644 --- a/config_manager_test.go +++ b/config_manager_test.go @@ -1,5 +1,3 @@ - -// +build !test package config_manager_go import ( @@ -34,7 +32,7 @@ func TestLoadConfig(t *testing.T) { assert.NotEqual(t, len(c.configs),0) observer.Notify(messages.CONFIGMANAGER_LOADED,c) - time.Sleep(2 * time.Second) + time.Sleep(1 * time.Second) }