-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_index.go
56 lines (45 loc) · 1.07 KB
/
mod_index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"html/template"
"log"
"net/http"
)
func indexPage(w http.ResponseWriter, r *http.Request) {
//this must add at begin of every session code
c, err := r.Cookie("session")
if err != nil || c.Value == "" {
http.Error(w, "Session expired", 401)
return
}
//handle GET/POST methods
if r.Method == "GET" {
//logout sequence
if r.FormValue("logout") == "true" {
cookie := http.Cookie{Name: "session", MaxAge: -1}
http.SetCookie(w, &cookie)
http.Redirect(w, r, "/", http.StatusFound)
log.Println(c.Value + " logout")
return
}
}
//build page content
b := `<pre>
Wellcome to simple applications framework.
This is a plugable environment with modules.
Modules can be added and removed.
You are now in index module connected as:
` + c.Value + ` from ` + r.Host +
`
In the top side you have some demo modules
Enjoy!`
//finally show the page
p := Page{
Title: "Index page",
Status: c.Value,
Body: template.HTML(b),
}
t.ExecuteTemplate(w, "index.html", p)
}
func init() {
http.HandleFunc("/index", indexPage)
}