From e4b0fcdd9df24edcf476285ab5fc7644b6dca08c Mon Sep 17 00:00:00 2001 From: lnino Date: Wed, 10 Apr 2024 19:53:00 +0200 Subject: [PATCH] base server and base html --- assets/css/index.css | 34 ++++++++++++++++++++++++++++++++++ assets/img/fakeimg.jpg | 0 controller/mainpage.go | 26 ++++++++++++++++++++++++++ controller/testpage.go | 26 ++++++++++++++++++++++++++ functions/notfound.go | 10 ++++++++++ go.mod | 3 +++ html/index.html | 9 +++++++++ html/test.html | 2 ++ main.go | 28 ++++++++++++++++++++++++++++ 9 files changed, 138 insertions(+) create mode 100644 assets/css/index.css create mode 100644 assets/img/fakeimg.jpg create mode 100644 controller/mainpage.go create mode 100644 controller/testpage.go create mode 100644 functions/notfound.go create mode 100644 go.mod create mode 100644 html/index.html create mode 100644 html/test.html create mode 100644 main.go diff --git a/assets/css/index.css b/assets/css/index.css new file mode 100644 index 0000000..09b5cb2 --- /dev/null +++ b/assets/css/index.css @@ -0,0 +1,34 @@ +body { + background-color: black; +} + +.Mino{ + color: white; + -webkit-animation: slide-in-left 0.9s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; + animation: slide-in-left 0.9s cubic-bezier(0.250, 0.460, 0.450, 0.940) both; + +} +@-webkit-keyframes slide-in-left { + 0% { + -webkit-transform: translateX(-1000px); + transform: translateX(-1000px); + opacity: 0; + } + 100% { + -webkit-transform: translateX(0); + transform: translateX(0); + opacity: 1; + } + } + @keyframes slide-in-left { + 0% { + -webkit-transform: translateX(-1000px); + transform: translateX(-1000px); + opacity: 0; + } + 100% { + -webkit-transform: translateX(0); + transform: translateX(0); + opacity: 1; + } + } \ No newline at end of file diff --git a/assets/img/fakeimg.jpg b/assets/img/fakeimg.jpg new file mode 100644 index 0000000..e69de29 diff --git a/controller/mainpage.go b/controller/mainpage.go new file mode 100644 index 0000000..09887a3 --- /dev/null +++ b/controller/mainpage.go @@ -0,0 +1,26 @@ +package controller + +import ( + infini "infini/functions" + "net/http" + "text/template" +) + +func MainPage(w http.ResponseWriter, r *http.Request) { + + if r.URL.Path != "/" { // met l'url de la page + infini.NotFound(w, r) // si l'url n'est pas bonne, renvoie sur la page d'erreur 404 + return + } + + tmpl, err := template.ParseFiles("html/index.html") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = tmpl.Execute(w, nil) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} diff --git a/controller/testpage.go b/controller/testpage.go new file mode 100644 index 0000000..a66641d --- /dev/null +++ b/controller/testpage.go @@ -0,0 +1,26 @@ +package controller + +import ( + infini "infini/functions" + "net/http" + "text/template" +) + +func TestPage(w http.ResponseWriter, r *http.Request) { + + if r.URL.Path != "/test" { // met l'url de la page + infini.NotFound(w, r) // si l'url n'est pas bonne, renvoie sur la page d'erreur 404 + return + } + + tmpl, err := template.ParseFiles("html/test.html") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = tmpl.Execute(w, nil) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} diff --git a/functions/notfound.go b/functions/notfound.go new file mode 100644 index 0000000..c9084a9 --- /dev/null +++ b/functions/notfound.go @@ -0,0 +1,10 @@ +package infini + +import "net/http" + +func NotFound(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) + + http.Redirect(w, r, "/", http.StatusSeeOther) + return +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..059432c --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module infini + +go 1.19 diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..5824289 --- /dev/null +++ b/html/index.html @@ -0,0 +1,9 @@ + + + Test + + + +

Mino

+ test + \ No newline at end of file diff --git a/html/test.html b/html/test.html new file mode 100644 index 0000000..7ceabbb --- /dev/null +++ b/html/test.html @@ -0,0 +1,2 @@ +back
+UwU \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..edc5047 --- /dev/null +++ b/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + controller "infini/controller" + "net/http" +) + +func main() { + + fs := http.FileServer(http.Dir("assets/")) + http.Handle("/assets/", http.StripPrefix("/assets/", fs)) + + http.HandleFunc("/", controller.MainPage) + http.HandleFunc("/test", controller.TestPage) + + // Print a message when the server is online + go func() { + fmt.Print("\n") + fmt.Println("Server is running on http://86.204.149.189:80") + fmt.Print("\n") + }() + + err := http.ListenAndServe("0.0.0.0:8080", nil) + if err != nil { + fmt.Println("Erreur lors du démarrage du serveur:", err) + } +}