feat: index and go server
This commit is contained in:
parent
67acc332bc
commit
e1caaac8a3
3 changed files with 73 additions and 0 deletions
47
server.go
Normal file
47
server.go
Normal 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
3
static/css/style.css
Normal file
|
@ -0,0 +1,3 @@
|
|||
h1 {
|
||||
color: red;
|
||||
}
|
23
static/index.html
Normal file
23
static/index.html
Normal 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 l’ID de la playlist (sans l’url): <input name="id" type="text" /></label> <br />
|
||||
<label for="type-id">Choississez un type d’ID:</label>
|
||||
<select name="type-id" id="type-id">
|
||||
<option value="playlist">Playlist</option>
|
||||
</select>
|
||||
<br />
|
||||
<input type="submit" value="Envoyer" />
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
<html>
|
Loading…
Reference in a new issue