houston server config에 storagepath 추가

This commit is contained in:
2023-06-13 10:10:30 +09:00
parent b14ad791df
commit 5c00ff73d7
6 changed files with 43 additions and 25 deletions

View File

@ -43,16 +43,22 @@ func NewHoustonHandler() HoustonServerWithHandler {
}
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
logger.Println("houstonHandler registed")
storagePath := loadConfig().StoragePath
logger.Println("houstonHandler registed. storage_path :", storagePath)
if len(storagePath) > 0 {
storagePath = storagePath + "/"
}
if len(prefix) > 0 {
prefix = "/" + prefix
}
serveMux.Handle(prefix, h)
fsx := http.FileServer(http.Dir("deploys"))
fsx := http.FileServer(http.Dir(storagePath + "deploys"))
serveMux.Handle(fmt.Sprintf("%s/deploys/", prefix), http.StripPrefix(fmt.Sprintf("%s/deploys/", prefix), fsx))
ufsx := http.FileServer(http.Dir("downloads"))
ufsx := http.FileServer(http.Dir(storagePath + "downloads"))
serveMux.Handle(fmt.Sprintf("%s/downloads/", prefix), http.StripPrefix(fmt.Sprintf("%s/downloads/", prefix), ufsx))
serveMux.HandleFunc(fmt.Sprintf("%s/upload", prefix), func(w http.ResponseWriter, r *http.Request) {
@ -69,8 +75,8 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
name := r.Header.Get("Houston-Service-Name")
version := r.Header.Get("Houston-Service-Version")
filename := r.Header.Get("Houston-Service-Filename")
dir := fmt.Sprintf("downloads/%s/%s", name, version)
if err := os.MkdirAll(dir, os.ModePerm); err == nil {
dir := fmt.Sprintf(storagePath+"downloads/%s/%s", name, version)
if err := os.MkdirAll(dir, 0775); err == nil {
file, _ := os.Create(path.Join(dir, filename))
if file != nil {
defer file.Close()