This commit is contained in:
10
main.go
10
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user