From 3278bca32f395aaaa9a861af340eb2202d17a9bb Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 22 Jun 2023 17:15:56 +0900 Subject: [PATCH] =?UTF-8?q?=ED=95=98=EB=93=9C=EC=BD=94=EB=94=A9=EB=90=9C?= =?UTF-8?q?=20=ED=8F=B4=EB=8D=94=EB=93=A4=20const=EB=A1=9C=20=EB=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/http_api.go | 16 +++++++++++----- server/http_handler.go | 7 ++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/server/http_api.go b/server/http_api.go index 3b4fceb..c49d18a 100644 --- a/server/http_api.go +++ b/server/http_api.go @@ -20,9 +20,15 @@ import ( 현재 접속 중인 Agent 목록을 보여줍니다. - http method : GET */ +const ( + sub_folder_name_deploys = string("_deploys") + sub_folder_name_downloads = string("_downloads") +) + func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) - enc.Encode(h.Operation().Hosts()) + allHosts := h.Operation().Hosts() + enc.Encode(allHosts) } func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) { @@ -84,7 +90,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque var filename string if version == "config" { - filename = path.Join(h.deployPath, name, version, "config.json") + filename = path.Join(h.deployPath, name, version, "config"+ext) } else { // deploys 폴더는 파일시스템 서비스이므로 다운로드 가능 filename = path.Join(h.deployPath, name, version, name+ext) @@ -180,14 +186,14 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) { configPath := "" if _, err := os.Stat(path.Join(h.deployPath, name, "config", "config.json")); err == nil || errors.Is(err, fs.ErrExist) { - configPath = path.Join("deploys", name, "config", "config.json") + configPath = path.Join(sub_folder_name_deploys, name, "config", "config.json") } h.Operation().Deploy(MakeDeployRequest( shared.DeployRequest{ Name: name, Version: version, - Url: path.Join("deploys", name, version, latestFilename), + Url: path.Join(sub_folder_name_deploys, name, version, latestFilename), Config: configPath, }, targets, @@ -357,7 +363,7 @@ func (h *houstonHandler) GetLogFileLinks(w http.ResponseWriter, r *http.Request) var out []string for _, lf := range logfiles { - out = append(out, path.Join("downloads", name, version, lf.Name())) + out = append(out, path.Join(sub_folder_name_downloads, name, version, lf.Name())) } enc := json.NewEncoder(w) diff --git a/server/http_handler.go b/server/http_handler.go index 42e7a09..546153d 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -45,9 +45,10 @@ func NewHoustonHandler() HoustonServerWithHandler { } func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error { - storagePath := loadServerConfig().StorageRoot - h.deployPath = path.Join(storagePath, "deploys") - h.downloadPath = path.Join(storagePath, "downloads") + config := loadServerConfig() + storagePath := config.StorageRoot + h.deployPath = path.Join(storagePath, sub_folder_name_deploys) + h.downloadPath = path.Join(storagePath, sub_folder_name_downloads) if err := os.MkdirAll(h.deployPath, 0775); err != nil { return err