feat: index and go server

This commit is contained in:
rick 2021-08-28 16:08:54 +02:00
parent 67acc332bc
commit e1caaac8a3
Signed by: Rick
GPG key ID: 2B593F087240EE99
3 changed files with 73 additions and 0 deletions

47
server.go Normal file
View file

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

3
static/css/style.css Normal file
View file

@ -0,0 +1,3 @@
h1 {
color: red;
}

23
static/index.html Normal file
View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="/css/style.css">
</head>
<html>
<body>
<h1>Spotify To Bandcamp</h1>
<p>Recherche dans une playlist les artistes se trouvant aussi sur Bandcamp !</p>
<hr />
<div>
<form action="/back" method="post">
<label>Saisir lID de la playlist (sans lurl): <input name="id" type="text" /></label> <br />
<label for="type-id">Choississez un type dID:</label>
<select name="type-id" id="type-id">
<option value="playlist">Playlist</option>
</select>
<br />
<input type="submit" value="Envoyer" />
</form>
</div>
</body>
<html>