From 455b1dc1843ac9cf7eb074ceef44fcfa606965ea Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 3 Jun 2023 19:20:16 +0300 Subject: [PATCH] init project --- go.mod | 3 +++ main.go | 17 ++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8aecc5e --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module cdn + +go 1.20 diff --git a/main.go b/main.go index 99c4323..a7a33f8 100644 --- a/main.go +++ b/main.go @@ -4,17 +4,17 @@ package main import ( "fmt" + "io" "log" "net/http" "os" - "io" "path/filepath" ) const ( - uploadPath = "uploads/" // Directory to store uploaded files - username = "admin" // Username for authentication - password = "password" // Password for authentication + uploadPath = "uploads" // Directory to store uploaded files + username = "admin" // Username for authentication + password = "password" // Password for authentication ) func main() { @@ -39,7 +39,7 @@ func serveCDN(w http.ResponseWriter, r *http.Request) { } // Get the requested file path - filePath := filepath.Join("src", r.URL.Path) + filePath := filepath.Join(uploadPath, r.URL.Path) // Check if the file exists _, err := os.Stat(filePath) @@ -112,10 +112,5 @@ func handleUpload(w http.ResponseWriter, r *http.Request) { func checkAuthentication(r *http.Request) bool { username, password, ok := r.BasicAuth() - if ok && username == "admin" && password == "password" { - log.Println("Authentication successful") - return true - } - log.Println("Authentication failed") - return false + return ok && username == username && password == password }