all repos — nds-converter @ 80af50e6b6c541e74a50bd8a18304c15a91823fa

A lightweight save converter for NDS and DeSmuME.

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	MaxFileSize *= MB
34
35	AdditionalBytes, _ = hex.DecodeString(AdditionalBytesHex)
36
37	http.HandleFunc("/", mainHandler)
38	println("Listening on port " + port)
39	http.ListenAndServe(":"+port, nil)
40}
41
42func mainHandler(w http.ResponseWriter, r *http.Request) {
43	switch r.Method {
44	case http.MethodGet:
45		getHandler(w)
46		return
47	case http.MethodPost:
48		postHandler(w, r)
49	default:
50		http.Error(w, "Method not supported", http.StatusBadRequest)
51	}
52}