Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replace gin to echo #33

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion service/osc/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func getDownloadList(fileList, objList []*utils.Object, dirPath string) ([]*util
for _, file := range fileList {
fileName, _ := filepath.Rel(dirPath, file.Key)
objName, _ := filepath.Rel(filepath.Base(dirPath), obj.Key)
if objName == fileName {
if strings.Contains(objName, fileName) {
chk = true
if obj.Size != file.Size {
downloadList = append(downloadList, obj)
Expand Down
2 changes: 1 addition & 1 deletion web/templates/mig-ncpToWindows.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h1 class="mt-4">마이그레이션 Naver Object Storage</h1>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-folder"></i></span>
<div class="form-floating">
<input type="text" class="form-control" id="mig-windows-path" name="path" value="/tmp/dummy" placeholder="디렉토리 경로">
<input type="text" class="form-control" id="mig-windows-path" name="path" value={{ .tmpPath }} placeholder="디렉토리 경로">
<label for="mig-windows-path">디렉토리 경로</label>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion web/templates/mig-s3ToWindows.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1 class="mt-4">마이그레이션 AWS S3</h1>
<label for="mig-aws-region" class="form-label">AWS S3</label>

<div class="form-floating">
<select class="form-select form-select-sm w-50" id="mig-aws-region" name="region">
<select class="form-select form-select-sm w-50" id="mig-aws-region" name="awsRegion">
<!-- <option selected>Region</option> -->
{{ range $index, $value := .Regions }}
<option value="{{ $value }}">{{ $value }}</option>
Expand Down
260 changes: 6 additions & 254 deletions websrc/controllers/generateHandlers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import (
"fmt"
"net/http"
"os"
"path/filepath"
Expand All @@ -10,18 +11,6 @@ import (
"github.com/labstack/echo/v4"
)

// func GenerateLinuxGetHandler() gin.HandlerFunc {
// return func(ctx *gin.Context) {
// logger := getLogger("genlinux")
// logger.Info("genlinux get page accessed")
// ctx.HTML(http.StatusOK, "index.html", map[string]interface{}{
// "Content": "Generate-Linux",
// "os": runtime.GOOS,
// "error": nil,
// })
// }
// }

func GenerateLinuxGetHandler(ctx echo.Context) error {

logger := getLogger("genlinux")
Expand All @@ -34,38 +23,6 @@ func GenerateLinuxGetHandler(ctx echo.Context) error {
})
}

// func GenerateLinuxPostHandler() gin.HandlerFunc {
// return func(ctx *gin.Context) {
// start := time.Now()

// logger, logstrings := pageLogInit("genlinux", "Create dummy data in linux", start)

// if !osCheck(logger, start, "linux") {
// ctx.JSONP(http.StatusBadRequest, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// params := getData("gen", ctx).(GenDataParams)

// if !dummyCreate(logger, start, params) {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// jobEnd(logger, "Successfully creating a dummy with Linux", start)
// ctx.JSONP(http.StatusOK, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// }
// }

func GenerateLinuxPostHandler(ctx echo.Context) error {

start := time.Now()
Expand All @@ -79,7 +36,6 @@ func GenerateLinuxPostHandler(ctx echo.Context) error {
})
}

// params := getData("gen", ctx).(GenDataParams)
params := GenDataParams{}
if err := ctx.Bind(params); err != nil {
return err
Expand All @@ -99,20 +55,6 @@ func GenerateLinuxPostHandler(ctx echo.Context) error {
})
}

// func GenerateWindowsGetHandler() gin.HandlerFunc {
// tmpPath := filepath.Join(os.TempDir(), "dummy")
// return func(ctx *gin.Context) {
// logger := getLogger("genwindows")
// logger.Info("genwindows get page accessed")
// ctx.HTML(http.StatusOK, "index.html", map[string]interface{}{
// "Content": "Generate-Windows",
// "os": runtime.GOOS,
// "tmpPath": tmpPath,
// "error": nil,
// })
// }
// }

func GenerateWindowsGetHandler(ctx echo.Context) error {

tmpPath := filepath.Join(os.TempDir(), "dummy")
Expand All @@ -127,57 +69,22 @@ func GenerateWindowsGetHandler(ctx echo.Context) error {
})
}

// func GenerateWindowsPostHandler() gin.HandlerFunc {
// return func(ctx *gin.Context) {
// start := time.Now()

// logger, logstrings := pageLogInit("genwindows", "Create dummy data in windows", start)

// if !osCheck(logger, start, "windows") {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// params := getData("gen", ctx).(GenDataParams)

// if !dummyCreate(logger, start, params) {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// jobEnd(logger, "Successfully creating a dummy with Windows", start)
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// }
// }

func GenerateWindowsPostHandler(ctx echo.Context) error {

start := time.Now()

logger, logstrings := pageLogInit("genwindows", "Create dummy data in windows", start)

if !osCheck(logger, start, "windows") {
fmt.Println("test")
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
"Result": logstrings.String(),
"Error": nil,
})

}

// params := getData("gen", ctx).(GenDataParams)
params := GenDataParams{}
if err := ctx.Bind(params); err != nil {
return err
}
params := getData("gen", ctx).(GenDataParams)

if !dummyCreate(logger, start, params) {
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
Expand All @@ -188,25 +95,12 @@ func GenerateWindowsPostHandler(ctx echo.Context) error {
}

jobEnd(logger, "Successfully creating a dummy with Windows", start)
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
return ctx.JSON(http.StatusOK, map[string]interface{}{
"Result": logstrings.String(),
"Error": nil,
})
}

// func GenerateS3GetHandler() gin.HandlerFunc {
// return func(ctx *gin.Context) {
// logger := getLogger("genS3")
// logger.Info("genS3 get page accessed")
// ctx.HTML(http.StatusOK, "index.html", map[string]interface{}{
// "Content": "Generate-S3",
// "os": runtime.GOOS,
// "Regions": GetAWSRegions(),
// "Error": nil,
// })
// }
// }

func GenerateS3GetHandler(ctx echo.Context) error {

logger := getLogger("genS3")
Expand All @@ -219,68 +113,12 @@ func GenerateS3GetHandler(ctx echo.Context) error {
})
}

// func GenerateS3PostHandler() gin.HandlerFunc {
// return func(ctx *gin.Context) {
// start := time.Now()

// logger, logstrings := pageLogInit("genS3", "Create dummy data and import to s3", start)

// params := getData("gen", ctx).(GenDataParams)

// tmpDir, ok := createDummyTemp(logger, start)
// if !ok {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }
// defer os.RemoveAll(tmpDir)
// params.DummyPath = tmpDir

// if !dummyCreate(logger, start, params) {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// awsOSC := getS3OSC(logger, start, "gen", params)
// if awsOSC == nil {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// if !oscImport(logger, start, "s3", awsOSC, params.DummyPath) {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// jobEnd(logger, "Dummy creation and import successful with s3", start)
// ctx.JSONP(http.StatusOK, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// }
// }

func GenerateS3PostHandler(ctx echo.Context) error {
start := time.Now()

logger, logstrings := pageLogInit("genS3", "Create dummy data and import to s3", start)

// params := getData("gen", ctx).(GenDataParams)
params := GenDataParams{}
if err := ctx.Bind(params); err != nil {
return err
}
params := getData("gen", ctx).(GenDataParams)

tmpDir, ok := createDummyTemp(logger, start)
if !ok {
Expand Down Expand Up @@ -325,19 +163,6 @@ func GenerateS3PostHandler(ctx echo.Context) error {
})
}

// func GenerateGCPGetHandler() gin.HandlerFunc {
// return func(ctx *gin.Context) {
// logger := getLogger("genGCP")
// logger.Info("genGCP get page accessed")
// ctx.HTML(http.StatusOK, "index.html", map[string]interface{}{
// "Content": "Generate-GCP",
// "os": runtime.GOOS,
// "Regions": GetGCPRegions(),
// "error": nil,
// })
// }
// }

func GenerateGCPGetHandler(ctx echo.Context) error {
logger := getLogger("genGCP")
logger.Info("genGCP get page accessed")
Expand All @@ -349,85 +174,12 @@ func GenerateGCPGetHandler(ctx echo.Context) error {
})
}

// func GenerateGCPPostHandler() gin.HandlerFunc {
// return func(ctx *gin.Context) {
// start := time.Now()

// logger, logstrings := pageLogInit("genGCP", "Create dummy data and import to gcp", start)

// params := GenDataParams{}
// if !getDataWithBind(logger, start, ctx, &params) {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// credTmpDir, credFileName, ok := gcpCreateCredFile(logger, start, ctx)
// if !ok {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }
// defer os.RemoveAll(credTmpDir)

// tmpDir, ok := createDummyTemp(logger, start)
// if !ok {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }
// defer os.RemoveAll(tmpDir)
// params.DummyPath = tmpDir

// if !dummyCreate(logger, start, params) {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// gcpOSC := getGCPCOSC(logger, start, "gen", params, credFileName)
// if gcpOSC == nil {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// if !oscImport(logger, start, "gcp", gcpOSC, params.DummyPath) {
// ctx.JSONP(http.StatusInternalServerError, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// return
// }

// jobEnd(logger, "Dummy creation and import successful with gcp", start)
// ctx.JSONP(http.StatusOK, map[string]interface{}{
// "Result": logstrings.String(),
// "Error": nil,
// })
// }
// }

func GenerateGCPPostHandler(ctx echo.Context) error {
start := time.Now()

logger, logstrings := pageLogInit("genGCP", "Create dummy data and import to gcp", start)

// params := getData("gen", ctx).(GenDataParams)
params := GenDataParams{}
if err := ctx.Bind(params); err != nil {
return err
}
params := getData("gen", ctx).(GenDataParams)

if !getDataWithBind(logger, start, ctx, &params) {
return ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
Expand Down
Loading