base server and base html

This commit is contained in:
lnino
2024-04-10 19:53:00 +02:00
commit e4b0fcdd9d
9 changed files with 138 additions and 0 deletions

34
assets/css/index.css Normal file
View File

@@ -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;
}
}

0
assets/img/fakeimg.jpg Normal file
View File

26
controller/mainpage.go Normal file
View File

@@ -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)
}
}

26
controller/testpage.go Normal file
View File

@@ -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)
}
}

10
functions/notfound.go Normal file
View File

@@ -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
}

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module infini
go 1.19

9
html/index.html Normal file
View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<head>
<title>Test</title>
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<h1 class="Mino">Mino</h1>
<a href="/test">test</a>
</body>

2
html/test.html Normal file
View File

@@ -0,0 +1,2 @@
<a href="/">back</a> <br>
UwU

28
main.go Normal file
View File

@@ -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)
}
}