From 368b4444a7d018b077907cfd3db2f393e2c527b7 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Sun, 26 May 2024 21:42:39 +0100 Subject: [PATCH] Why was this not deleted I do not know --- Makefile | 9 --------- go.mod | 9 --------- go.sum | 6 ------ main.go | 49 --------------------------------------------- usefulQueries.sql | 22 -------------------- views/editorPage.go | 19 ------------------ views/loginPage.go | 23 --------------------- views/templating.go | 36 --------------------------------- 8 files changed, 173 deletions(-) delete mode 100644 Makefile delete mode 100644 go.mod delete mode 100644 go.sum delete mode 100644 main.go delete mode 100644 usefulQueries.sql delete mode 100644 views/editorPage.go delete mode 100644 views/loginPage.go delete mode 100644 views/templating.go diff --git a/Makefile b/Makefile deleted file mode 100644 index 3cf9f0a..0000000 --- a/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -build: clean - mkdir build - go build -o build/frontend - cp -r ./assets build - touch build/data.db - sqlite3 build/data.db < ./usefulQueries.sql - -clean: - rm -r build diff --git a/go.mod b/go.mod deleted file mode 100644 index a38c52a..0000000 --- a/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module thermalFax - -go 1.22.2 - -require ( - github.com/golang-jwt/jwt/v4 v4.5.0 - github.com/mattn/go-sqlite3 v1.14.22 - golang.org/x/crypto v0.22.0 -) diff --git a/go.sum b/go.sum deleted file mode 100644 index 839f752..0000000 --- a/go.sum +++ /dev/null @@ -1,6 +0,0 @@ -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= -github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= diff --git a/main.go b/main.go deleted file mode 100644 index 132fd55..0000000 --- a/main.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - "thermalFax/controllers" -) - -func checkMethod(method string, r *http.Request) bool { - return r.Method == method -} - -func main() { - // GET calls - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if !checkMethod(http.MethodGet, r) { - w.WriteHeader(http.StatusMethodNotAllowed) - return - } - - controllers.EditorPage(w, r) - }) - - // POST calls - http.HandleFunc("/send-fax", func(w http.ResponseWriter, r *http.Request) { - if !checkMethod(http.MethodPost, r) { - w.WriteHeader(http.StatusMethodNotAllowed) - return - } - - controllers.SendFax(w, r) - }) - - http.HandleFunc("/send-login", func(w http.ResponseWriter, r *http.Request) { - if !checkMethod(http.MethodPost, r) { - w.WriteHeader(http.StatusMethodNotAllowed) - return - } - - controllers.Authenticate(w, r) - }) - - // Serve the CSS and JS files, we might have to change this - http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets")))) - - fmt.Println("Starting server on port 8083") - log.Fatal(http.ListenAndServe(":8083", nil)) -} diff --git a/usefulQueries.sql b/usefulQueries.sql deleted file mode 100644 index 63d9f87..0000000 --- a/usefulQueries.sql +++ /dev/null @@ -1,22 +0,0 @@ --- Generate a password --- htpasswd -bnBC 10 "" kika | tr -d ':\n' - -CREATE TABLE IF NOT EXISTS users( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL UNIQUE, - password TEXT NOT NULL -); - -CREATE TABLE IF NOT EXISTS sessions( - id INTEGER PRIMARY KEY AUTOINCREMENT, - user TEXT NOT NULL, - token TEXT NOT NULL, - expires INTEGER -); - -INSERT INTO - users(name, password) - values( - 'user', - '$2y$10$E9TqLeXWU85ZVTz7TCyTbu1S.ZaNV6v6DOmrbxqfMm/ADMkBKLP.O' - ); \ No newline at end of file diff --git a/views/editorPage.go b/views/editorPage.go deleted file mode 100644 index b724b10..0000000 --- a/views/editorPage.go +++ /dev/null @@ -1,19 +0,0 @@ -package views - -import "net/http" - -func EditorPage(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - - mainPage := HtmlTemplate("./assets/htmx/terminal.tmpl", map[string]interface{}{ - "content": HtmlTemplate("./assets/htmx/editor.html", nil), - "renderNavBar": true, - "page": "fax", - }) - - _, err := w.Write([]byte(mainPage)) - if err != nil { - http.Error(w, "Internal error", http.StatusInternalServerError) - return - } -} diff --git a/views/loginPage.go b/views/loginPage.go deleted file mode 100644 index a5b1fcf..0000000 --- a/views/loginPage.go +++ /dev/null @@ -1,23 +0,0 @@ -package views - -import "net/http" - -func LoginPage(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - - loginTemplate := HtmlTemplate("./assets/htmx/login.html", map[string]interface{}{ - "script": true, - }) - - loginPage := HtmlTemplate("./assets/htmx/terminal.tmpl", map[string]interface{}{ - "content": loginTemplate, - "renderNavBar": true, - "page": "fax", - }) - - _, err := w.Write([]byte(loginPage)) - if err != nil { - http.Error(w, "Internal error", http.StatusInternalServerError) - return - } -} diff --git a/views/templating.go b/views/templating.go deleted file mode 100644 index 4d0dd77..0000000 --- a/views/templating.go +++ /dev/null @@ -1,36 +0,0 @@ -package views - -import ( - "bytes" - "html/template" - "log" - "path" -) - -// func loadFile(path string) []byte { -// file, err := os.ReadFile(path) -// if err != nil { -// log.Printf("Unable to open file: %s\n", path) -// } -// return file -// } - -func HtmlTemplate(file string, data map[string]interface{}) template.HTML { - templateName := path.Base(file) - tmpl, err := template.New(templateName).ParseFiles(file) - if err != nil { - panic(err) - } - - // Use a bytes.Buffer to store the rendered output - var renderedOutput bytes.Buffer - - // Render the template - err = tmpl.ExecuteTemplate(&renderedOutput, templateName, data) - if err != nil { - log.Fatalf("Template execution: %v", err) - } - - // Now, renderedOutput holds the rendered template - return template.HTML(renderedOutput.String()) -}