diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index f6a1046..0000000 --- a/.drone.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -kind: pipeline -type: docker -name: default - - - -steps: -- name: staticcheck - image: golang:1.18.3-alpine3.16 - commands: - - apk add --no-cache git~=2 staticcheck~=2022 gcc~=11 libc-dev~=0 - - staticcheck -- name: build - image: plugins/docker - settings: - username: - from_secret: DOCKER_USERNAME - password: - from_secret: DOCKER_PASSWORD - repo: 185504a9/sfu - tags: latest - target: run_prod - depends_on: - - staticcheck \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a1cc146..cda8681 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ARG uid=1000 RUN mkdir -p "$APP_ROOT" \ && addgroup --system sfu -g $gid \ && adduser -h "$APP_ROOT" --disabled-password --system -u $uid --ingroup sfu sfu \ - && apk add --no-cache curl~=7 + && apk add curl~=7 WORKDIR "$APP_ROOT" USER sfu:sfu diff --git a/README.md b/README.md index 7d25ddb..c2a337c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # sfu -[![Build Status](https://qa.roboces.dev/api/badges/catalin/sfu/status.svg)](https://qa.roboces.dev/catalin/sfu) simple requirementsless, authenticationless file upload server diff --git a/handlers.go b/handlers.go index ecb42df..348a913 100644 --- a/handlers.go +++ b/handlers.go @@ -10,7 +10,7 @@ import ( ) func downloadFile(w http.ResponseWriter, req *http.Request, fileName string) { - Info.Printf("server: will download %v\n", fileName) + Info.Println(fmt.Sprintf("server: will download %v", fileName)) file, err := os.Open(fmt.Sprintf("%v/%v", SFU_FILES_DIR, fileName)) if err != nil { Error.Println(err) @@ -34,9 +34,9 @@ func fileExists(fileName string) bool { } func deleteFile(w http.ResponseWriter, req *http.Request, fileName string) { - Info.Printf("server: will delete %v\n", fileName) + Info.Println(fmt.Sprintf("server: will delete %v", fileName)) if !fileExists(fileName) { - Error.Printf("%v does not exist\n", fileName) + Error.Println(fmt.Sprintf("%v does not exist", fileName)) http.Error(w, "File not found", http.StatusNotFound) return } @@ -59,12 +59,12 @@ func uploadFile(w http.ResponseWriter, req *http.Request) { fileExists := fileExists(fileHeader.Filename) forceOverwrite := req.FormValue("force") if fileExists && forceOverwrite != "true" { - Error.Printf("file %v already exists\n", fileHeader.Filename) + Error.Println(fmt.Sprintf("file %v already exists", fileHeader.Filename)) http.Error(w, "File already exists", http.StatusConflict) return } if !fileExists || (forceOverwrite == "true" && fileExists) { - Info.Printf("server: will upload %v\n", fileHeader.Filename) + Info.Println(fmt.Sprintf("server: will upload %v", fileHeader.Filename)) out, err := os.Create(fmt.Sprintf("%v/%v", SFU_FILES_DIR, fileHeader.Filename)) if err != nil { Error.Println(err) @@ -83,14 +83,15 @@ func uploadFile(w http.ResponseWriter, req *http.Request) { return } http.Error(w, "internal server error", http.StatusInternalServerError) + return } func listFiles(w http.ResponseWriter, req *http.Request) { - Info.Printf("server: will list uploaded files on %v\n", SFU_FILES_DIR) + Info.Println(fmt.Sprintf("server: will list uploaded files on %v", SFU_FILES_DIR)) files, err := ioutil.ReadDir(SFU_FILES_DIR) if err != nil { - Warning.Printf("%v does not exist\n", SFU_FILES_DIR) - Info.Printf("will create %v\n", SFU_FILES_DIR) + Warning.Println(fmt.Sprintf("%v does not exist", SFU_FILES_DIR)) + Info.Println(fmt.Sprintf("will create %v", SFU_FILES_DIR)) _ = os.Mkdir(SFU_FILES_DIR, os.ModePerm) } fmt.Fprint(w, "
    ") diff --git a/main.go b/main.go index 55f5e42..b673228 100644 --- a/main.go +++ b/main.go @@ -12,10 +12,10 @@ var SFU_FILES_DIR string = getEnvvar("SFU_FILES_DIR") var SFU_PORT string = getEnvvar("SFU_PORT") func getEnvvar(envvar_name string) string { - Info.Printf("getting envvar %v\n", envvar_name) + Info.Printf("getting envvar %v", envvar_name) envvar_value, isSet := os.LookupEnv(envvar_name) if !isSet { - Error.Printf("%v is not set\n", envvar_name) + Error.Println(fmt.Sprintf("%v is not set", envvar_name)) os.Exit(1) } return envvar_value @@ -33,9 +33,9 @@ func emptyArray(s []string) []string { func routeFiles(w http.ResponseWriter, r *http.Request) { path := r.URL.Path - Info.Printf("received %v on %v", r.Method, path) + Info.Println(fmt.Sprintf("received %v on %v", r.Method, path)) paths := emptyArray(strings.Split(path, "/")) - Info.Printf("paths %v\n", paths) + Info.Println(fmt.Sprintf("paths %v", paths)) switch len(paths) { case 1: switch r.Method { @@ -45,8 +45,8 @@ func routeFiles(w http.ResponseWriter, r *http.Request) { uploadFile(w, r) default: http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) - Warning.Printf("%v not allowed\n", r.Method) - Error.Printf("will return %v\n", http.StatusMethodNotAllowed) + Warning.Println(fmt.Sprintf("%v not allowed", r.Method)) + Error.Println(fmt.Sprintf("will return %v", http.StatusMethodNotAllowed)) } return case 2: @@ -57,8 +57,8 @@ func routeFiles(w http.ResponseWriter, r *http.Request) { deleteFile(w, r, paths[1]) default: http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) - Warning.Printf("%v not allowed\n", r.Method) - Error.Printf("will return %v\n", http.StatusMethodNotAllowed) + Warning.Println(fmt.Sprintf("%v not allowed", r.Method)) + Error.Println(fmt.Sprintf("will return %v", http.StatusMethodNotAllowed)) } default: http.Error(w, "Not found", http.StatusNotFound) @@ -87,10 +87,10 @@ func main() { mux := http.NewServeMux() mux.HandleFunc("/", route) port := fmt.Sprintf(":%v", SFU_PORT) - Info.Printf("running SFU on port %v\n", port) + Info.Println(fmt.Sprintf("running SFU on port %v", port)) err := http.ListenAndServe(port, mux) if err != nil { - Error.Printf("%v port may not be available\n", port) + Error.Println(fmt.Sprintf("%v port may not be available", port)) os.Exit(1) } }