mirror of
https://github.com/NotAShelf/go-cdn.git
synced 2024-11-23 00:10:43 +00:00
init project
This commit is contained in:
parent
eb39e534ef
commit
455b1dc184
2 changed files with 9 additions and 11 deletions
3
go.mod
Normal file
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module cdn
|
||||||
|
|
||||||
|
go 1.20
|
17
main.go
17
main.go
|
@ -4,17 +4,17 @@ 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
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -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
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue