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 ( import (
"fmt" "fmt"
"io"
"log" "log"
"net/http" "net/http"
"os" "os"
"io"
"path/filepath" "path/filepath"
) )
const ( const (
uploadPath = "uploads/" // Directory to store uploaded files uploadPath = "uploads" // Directory to store uploaded files
username = "admin" // Username for authentication username = "admin" // Username for authentication
password = "password" // Password for authentication password = "password" // Password for authentication
) )
@ -39,7 +39,7 @@ func serveCDN(w http.ResponseWriter, r *http.Request) {
} }
// Get the requested file path // Get the requested file path
filePath := filepath.Join("src", r.URL.Path) filePath := filepath.Join(uploadPath, r.URL.Path)
// Check if the file exists // Check if the file exists
_, err := os.Stat(filePath) _, err := os.Stat(filePath)
@ -112,10 +112,5 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
func checkAuthentication(r *http.Request) bool { func checkAuthentication(r *http.Request) bool {
username, password, ok := r.BasicAuth() username, password, ok := r.BasicAuth()
if ok && username == "admin" && password == "password" { return ok && username == username && password == password
log.Println("Authentication successful")
return true
}
log.Println("Authentication failed")
return false
} }