nds-converter.go (view raw)
1package main
2
3import (
4 "encoding/hex"
5 "net/http"
6 "os"
7 "strconv"
8
9 "github.com/joho/godotenv"
10)
11
12const (
13 DefaultPort = "1111"
14)
15
16func main() {
17 // Load the .env file
18 err := godotenv.Load()
19 if err != nil {
20 println("Could not load .env file")
21 }
22
23 port := os.Getenv("PORT")
24 if port == "" {
25 port = DefaultPort
26 }
27
28 fileSizeString := os.Getenv("MAX_SIZE_MB")
29 MaxFileSize, err = strconv.ParseInt(fileSizeString, 10, 64)
30 if err != nil {
31 MaxFileSize = DefaultMaxFileSize
32 }
33 println("Max file size:", MaxFileSize, "MB.")
34 MaxFileSize *= MB
35
36 AdditionalBytes, _ = hex.DecodeString(AdditionalBytesHex)
37
38 http.HandleFunc("/", mainHandler)
39 println("Listening on port " + port)
40 http.ListenAndServe(":"+port, nil)
41}
42
43func mainHandler(w http.ResponseWriter, r *http.Request) {
44 switch r.Method {
45 case http.MethodGet:
46 getHandler(w)
47 return
48 case http.MethodPost:
49 postHandler(w, r)
50 default:
51 http.Error(w, "Method not supported", http.StatusBadRequest)
52 }
53}