-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
36 lines (31 loc) · 779 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
36
package main
import (
"fmt"
"github.com/gorilla/context"
"github.com/gorilla/sessions"
"io"
"net/http"
)
var store = sessions.NewCookieStore([]byte("secret-password"))
func setSession(res http.ResponseWriter, req *http.Request) {
session, _ := store.Get(req, "session")
if req.FormValue("email") != "" {
session.Values["email"] = req.FormValue("email")
}
session.Save(req, res)
io.WriteString(res, `<!DOCTYPE html>
<html>
<body>
<form method="POST">
<p>`+fmt.Sprint(session.Values["email"])+`</p>
<p>Enter Your Email:</p>
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>`)
}
func main() {
http.HandleFunc("/", setSession)
http.ListenAndServe(":8080", context.ClearHandler(http.DefaultServeMux))
}