forked from GoesToEleven/GolangTraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
35 lines (30 loc) · 726 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
"github.com/gorilla/sessions"
"io"
"net/http"
)
var store = sessions.NewCookieStore([]byte("secret-password"))
func main() {
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
session, _ := store.Get(req, "session")
if req.FormValue("email") != "" {
// check password
session.Values["email"] = req.FormValue("email")
}
session.Save(req, res)
io.WriteString(res, `<!DOCTYPE html>
<html>
<body>
<form method="POST">
`+fmt.Sprint(session.Values["email"])+`
<input type="email" name="email">
<input type="password" name="password">
<input type="submit">
</form>
</body>
</html>`)
})
http.ListenAndServe(":9000", nil)
}