From e1caaac8a328da29cbeb74e3a8356eed0bfe0ad8 Mon Sep 17 00:00:00 2001 From: rick Date: Sat, 28 Aug 2021 16:08:54 +0200 Subject: [PATCH] feat: index and go server --- server.go | 47 ++++++++++++++++++++++++++++++++++++++++++++ static/css/style.css | 3 +++ static/index.html | 23 ++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 server.go create mode 100644 static/css/style.css create mode 100644 static/index.html diff --git a/server.go b/server.go new file mode 100644 index 0000000..ca54373 --- /dev/null +++ b/server.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func formHandler(w http.ResponseWriter, r *http.Request) { + if err := r.ParseForm(); err != nil { + fmt.Fprintf(w, "ParseForm() err: %v", err) + return + } + + fmt.Fprintf(w, "POST request successful") + type_id := r.FormValue("type-id") + id := r.FormValue("id") + + fmt.Fprintf(w, "Type ID = %s\n", type_id) + fmt.Fprintf(w, "ID = %s\n", id) +} + +func index(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/hello" { + http.Error(w, "404", http.StatusNotFound) + return + } + + if r.Method != "GET" { + http.Error(w, "Use GET pls", http.StatusNotFound) + return + } + + fmt.Fprintf(w, "Helo!") +} + +func main() { + fileServer := http.FileServer(http.Dir("./static")) + http.Handle("/", fileServer) + http.HandleFunc("/hello", index) + http.HandleFunc("/back", formHandler) + + fmt.Printf("Starting the server…\n") + if err := http.ListenAndServe(":8080", nil); err != nil { + log.Fatal(err) + } +} diff --git a/static/css/style.css b/static/css/style.css new file mode 100644 index 0000000..d224431 --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,3 @@ +h1 { + color: red; +} diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..8ebea22 --- /dev/null +++ b/static/index.html @@ -0,0 +1,23 @@ + + + + + + +

Spotify To Bandcamp

+

Recherche dans une playlist les artistes se trouvant aussi sur Bandcamp !

+
+ +
+
+
+ + +
+ +
+
+ +