deploy, download 경로 지정

This commit is contained in:
2023-06-13 11:04:30 +09:00
parent 5c00ff73d7
commit 5f1b23ed80
2 changed files with 18 additions and 17 deletions

View File

@ -24,7 +24,9 @@ type HoustonServerWithHandler interface {
type houstonHandler struct {
HoustonServer
methods map[string]reflect.Method
methods map[string]reflect.Method
deployPath string
downloadPath string
}
func NewHoustonHandler() HoustonServerWithHandler {
@ -44,21 +46,20 @@ func NewHoustonHandler() HoustonServerWithHandler {
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
storagePath := loadConfig().StoragePath
h.deployPath = path.Join(storagePath, "deploys")
h.downloadPath = path.Join(storagePath, "downloads")
logger.Println("houstonHandler registed. storage_path :", storagePath)
if len(storagePath) > 0 {
storagePath = storagePath + "/"
}
logger.Printf("houstonHandler registed. deployPath : %s, downloadPath : %s", h.deployPath, h.downloadPath)
if len(prefix) > 0 {
prefix = "/" + prefix
}
serveMux.Handle(prefix, h)
fsx := http.FileServer(http.Dir(storagePath + "deploys"))
fsx := http.FileServer(http.Dir(h.deployPath))
serveMux.Handle(fmt.Sprintf("%s/deploys/", prefix), http.StripPrefix(fmt.Sprintf("%s/deploys/", prefix), fsx))
ufsx := http.FileServer(http.Dir(storagePath + "downloads"))
ufsx := http.FileServer(http.Dir(h.downloadPath))
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) {
@ -75,7 +76,7 @@ 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(storagePath+"downloads/%s/%s", name, version)
dir := path.Join(h.downloadPath, name, version)
if err := os.MkdirAll(dir, 0775); err == nil {
file, _ := os.Create(path.Join(dir, filename))
if file != nil {