From: 2weiEmu Date: Wed, 22 Jan 2025 14:23:42 +0000 (+0100) Subject: inital structrure X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=1b6c2fd0be1fba6831ef379dbdb78d0ca1bc79f0;p=creative-path-pep.git inital structrure --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cf5a684 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +OBJECTS = . +CMD = go +TARGET = build/pep + +DEPLOY_PORT = 80 +DEPLOY_BASE = + +default: $(OBJECTS) + $(CMD) run $(OBJECTS) + +build: $(OBJECTS) + $(CMD) build -o $(TARGET) $(OBJECTS) + +test: $(OBJECTS) + $(CMD) test -coverprofile -v ./... diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..827b8db --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module creative-path-pep + +go 1.23.4 + +require github.com/gorilla/mux v1.8.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7128337 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= diff --git a/log/pep.log b/log/pep.log new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go new file mode 100644 index 0000000..be1b7ee --- /dev/null +++ b/main.go @@ -0,0 +1,72 @@ +package main + +import ( + "flag" + "fmt" + "log" + "net/http" + "os" + "strconv" + + "creative-path-pep/pkg/constants" + "creative-path-pep/pkg/handlers" + "creative-path-pep/pkg/logger" + + "github.com/gorilla/mux" +) + +func main() { + paramDeploy := flag.Bool( + "d", false, "A flag specifying the deploy mode of the server.") + paramPort := flag.Int( + "p", 8000, "The port the server should be deployed on.") + _ = flag.String( + "base", "localhost:8000", "Where websockets should connect.") + cert := flag.String("c", "", "State the certificate location") + secret := flag.String("k", "", "State the private key location") + flag.Parse() + + logFile, err := os.OpenFile(constants.MainLogFile, os.O_APPEND | os.O_RDWR, 0664) + if err != nil { + fmt.Println("[ERROR] Failed to open main log file.") + panic("Could not open log file.") + } + defer logFile.Close() + + logger.InfoLog = log.New(logFile, "[INFO] ", logger.LoggerFlags) + logger.RequestLog = log.New(logFile, "[REQUEST] ", logger.LoggerFlags) + logger.ErrorLog = log.New(logFile, "[ERROR] ", logger.LoggerFlags) + + cssDir := http.Dir("static/css") + imgDir := http.Dir("static/images") + jsDir := http.Dir("static/js") + fontsDir := http.Dir("static/fonts") + + _ = "none" + if *paramDeploy { + _ = "ssl" + } + + router := mux.NewRouter() + router.HandleFunc("/", handlers.HandleIndex) + + http.Handle("/", router) + http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(cssDir))) + http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(imgDir))) + http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(jsDir))) + http.Handle("/fonts/", http.StripPrefix("/fonts/", http.FileServer(fontsDir))) + + listenPort := ":" + strconv.Itoa(*paramPort) + if *paramDeploy { + fmt.Println("Began listening (SSL) on port:", listenPort); + err = http.ListenAndServeTLS(listenPort, *cert, *secret, nil) + + } else { + fmt.Println("Began listening on port:", listenPort); + err = http.ListenAndServe(listenPort, nil) + } + + if err != nil { + logger.ErrorLog.Fatalf("Listen and serve failed with:", err) + } +} diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go new file mode 100644 index 0000000..f3f86cc --- /dev/null +++ b/pkg/constants/constants.go @@ -0,0 +1,3 @@ +package constants + +const MainLogFile = "./log/pep.log" diff --git a/pkg/handlers/handlers.go b/pkg/handlers/handlers.go new file mode 100644 index 0000000..e98c0cb --- /dev/null +++ b/pkg/handlers/handlers.go @@ -0,0 +1,19 @@ +package handlers + +import ( + "net/http" + "text/template" +) + +type IndexPageStruct struct { +} + +var indexTemplate, err = template.ParseFiles("static/templates/index.html") + +func HandleIndex(w http.ResponseWriter, r *http.Request) { + err := indexTemplate.Execute(w, IndexPageStruct{}) + + if err != nil { + w.Write([]byte("error oopsie woopsie")) + } +} diff --git a/pkg/lerror/lerror.go b/pkg/lerror/lerror.go new file mode 100644 index 0000000..477a92f --- /dev/null +++ b/pkg/lerror/lerror.go @@ -0,0 +1,3 @@ +package lerror + + diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go new file mode 100644 index 0000000..94cc37c --- /dev/null +++ b/pkg/logger/logger.go @@ -0,0 +1,9 @@ +package logger + +import ( + "log" +) + +var InfoLog, RequestLog, ErrorLog *log.Logger + +const LoggerFlags = log.LstdFlags | log.Lshortfile | log.Ldate | log.Ltime diff --git a/static/css/index.css b/static/css/index.css new file mode 100644 index 0000000..966df95 --- /dev/null +++ b/static/css/index.css @@ -0,0 +1,41 @@ +:root { + --text: #050315; + --bg: #FF007F; + --bg-sec: #FF7C91; + --primary: #DFFF00; + --sec: #FF6F20; + --acc: #00BFFF; + --white: #FFFFFF; +} + +@font-face { + src: url("/fonts/JosefinSans_VariableFont_wght.ttf"); + font-family: JosefinSans; + font-weight: 400; + font-style: normal; +} + +* { + font-family: JosefinSans; +} + +body { + background-color: var(--white); + min-width: 100vw; + min-height: 100vh; + + margin: 0; + padding: 0; +} + +#sidebar { + position: fixed; + width: 20%; + height: 100vh; + background-color: var(--bg); + + box-shadow: 4px 4px 0px var(--text); + + border-right: 3px solid black; +} + diff --git a/static/fonts/JosefinSans_Italic_VariableFont_wght.ttf b/static/fonts/JosefinSans_Italic_VariableFont_wght.ttf new file mode 100644 index 0000000..d2d2dd6 Binary files /dev/null and b/static/fonts/JosefinSans_Italic_VariableFont_wght.ttf differ diff --git a/static/fonts/JosefinSans_VariableFont_wght.ttf b/static/fonts/JosefinSans_VariableFont_wght.ttf new file mode 100644 index 0000000..00ea1e7 Binary files /dev/null and b/static/fonts/JosefinSans_VariableFont_wght.ttf differ diff --git a/static/templates/index.html b/static/templates/index.html new file mode 100644 index 0000000..ffee1c1 --- /dev/null +++ b/static/templates/index.html @@ -0,0 +1,22 @@ + + + + + + + + FacCalc + + + + + + + +