init project

This commit is contained in:
NotAShelf 2023-06-03 19:20:16 +03:00
parent eb39e534ef
commit 455b1dc184
No known key found for this signature in database
GPG key ID: F0D14CCB5ED5AA22
2 changed files with 9 additions and 11 deletions

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module cdn
go 1.20

13
main.go
View file

@ -4,15 +4,15 @@ package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"io"
"path/filepath"
)
const (
uploadPath = "uploads/" // Directory to store uploaded files
uploadPath = "uploads" // Directory to store uploaded files
username = "admin" // Username for authentication
password = "password" // Password for authentication
)
@ -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
}