Skip to content

Commit

Permalink
Added additional judgements for different operating systems. Added th…
Browse files Browse the repository at this point in the history
…e ability to customise ports.
  • Loading branch information
Yuzu815 committed Jul 25, 2022
1 parent 0461dca commit 0fbd0eb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src-web/cores/Utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
)

func getRandomStringHex(strLen int) string {
Expand Down Expand Up @@ -102,7 +103,13 @@ func ZipCompress(srcDir, zipFileName, randomUID string) {
}
header, _ := zip.FileInfoHeader(info)
if info.IsDir() {
header.Name += `/`
var specialChar string
if runtime.GOOS == "windows" {
specialChar = "\\"
} else {
specialChar = "/"
}
header.Name += specialChar
} else {
header.Name = removeRedundantPartOfTheFileName(path)
header.Method = zip.Deflate
Expand Down Expand Up @@ -132,7 +139,14 @@ func ZipCompress(srcDir, zipFileName, randomUID string) {
// removeRedundantPartOfTheFileName \folder1\folder2\folder3\xxx.cpp -> xxx.cpp
func removeRedundantPartOfTheFileName(fileName string) string {
length := len(fileName) - 1
for fileName[length] != '\\' {
// TODO E: 最後在Linux平臺上會出現錯誤,疑似路徑表示方式不同
var specialChar uint8
if runtime.GOOS == "windows" {
specialChar = '\\'
} else {
specialChar = '/'
}
for fileName[length] != specialChar {
length--
}
return fileName[length+1:]
Expand Down
21 changes: 19 additions & 2 deletions src-web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@ package main

import (
"Codeforces-ContestCodeDownload/src-web/router"
"fmt"
"github.com/gin-gonic/gin"
"os"
"strconv"
)

func main() {
gin.SetMode(gin.DebugMode)
gin.SetMode(gin.ReleaseMode)
RouterServer := router.SetupRouter()
_ = RouterServer.Run(":8080")
port := portArg()
fmt.Println("[Listen] PORT" + port)
_ = RouterServer.Run(port)
}

func portArg() string {
args := os.Args
argNum := len(args)
if argNum == 2 {
argVal, err := strconv.Atoi(args[1])
if err == nil && argVal >= 1 && argVal <= 65535 {
return ":" + args[1]
}
}
return ":8080"
}

0 comments on commit 0fbd0eb

Please sign in to comment.