Merge files into main.go
This commit is contained in:
parent
8ded814424
commit
4f553f6022
11
home.go
11
home.go
@ -1,11 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Home(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Serve home page to %s: %s [%s]\n", r.Header.Get("X-Forwarded-For"), r.URL.Path, r.UserAgent())
|
||||
http.ServeFile(w, r, "home.html")
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
Aidez-moi à améliorer ce cours en donnant votre avis.
|
||||
</p>
|
||||
|
||||
<form method="post" action="/vote">
|
||||
<form method="post" action="vote">
|
||||
|
||||
<div class="form-group">
|
||||
<h3>Quel est le cours/TP que vous avez préféré ?</h3>
|
||||
|
16
main.go
16
main.go
@ -7,13 +7,27 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Home(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
r.ParseForm()
|
||||
log.Printf("Handling new vote from %s: %s [%s]\n", r.Header.Get("X-Forwarded-For"), r.URL.Path, r.UserAgent())
|
||||
for k, v := range r.PostForm {
|
||||
log.Println(k + ":", v)
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, "thanks.html")
|
||||
} else {
|
||||
log.Printf("Serve home page to %s: %s [%s]\n", r.Header.Get("X-Forwarded-For"), r.URL.Path, r.UserAgent())
|
||||
http.ServeFile(w, r, "home.html")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
var bind = flag.String("bind", "0.0.0.0:8081", "Bind port/socket")
|
||||
flag.Parse()
|
||||
|
||||
log.Println("Registering handlers...")
|
||||
http.HandleFunc("/", Home)
|
||||
http.HandleFunc("/vote", Vote)
|
||||
log.Println(fmt.Sprintf("Ready, listening on %s", *bind))
|
||||
if err := http.ListenAndServe(*bind, nil); err != nil {
|
||||
log.Fatal("Unable to listen and serve: ", err)
|
||||
|
20
vote.go
20
vote.go
@ -1,20 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Vote(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
r.ParseForm()
|
||||
log.Printf("Handling new vote from %s: %s [%s]\n", r.Header.Get("X-Forwarded-For"), r.URL.Path, r.UserAgent())
|
||||
for k, v := range r.PostForm {
|
||||
log.Println(k + ":", v)
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, "thanks.html")
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user