apikey
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 32s

This commit is contained in:
matst80
2025-05-15 19:47:49 +02:00
parent 8715c7ea34
commit fa47d75541
2 changed files with 10 additions and 11 deletions

10
main.go
View File

@@ -6,6 +6,7 @@ import (
"log"
"net/http"
"net/url"
"os"
"strings"
"git.tornberg.me/go-persist/pkg/storage"
@@ -132,8 +133,10 @@ func esimateMimeType(filename string) string {
return "application/octet-stream"
}
var apiKey = os.Getenv("API_KEY")
func main() {
// Initialize the application
rootDir, err := storage.NewDiskStorage([]string{})
if err != nil {
log.Fatal(err)
@@ -188,6 +191,11 @@ func main() {
json.NewEncoder(w).Encode(content)
} else {
defer r.Body.Close()
authKey := r.Header.Get("Authorization")
if authKey != apiKey {
w.WriteHeader(http.StatusUnauthorized)
return
}
data, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)