File tree Expand file tree Collapse file tree 2 files changed +8
-15
lines changed Expand file tree Collapse file tree 2 files changed +8
-15
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "github.com/satori/go.uuid"
5
4
"html/template"
6
5
"net/http"
6
+
7
+ uuid "github.com/satori/go.uuid"
7
8
)
8
9
9
10
type user struct {
@@ -30,12 +31,12 @@ func main() {
30
31
}
31
32
32
33
func index (w http.ResponseWriter , req * http.Request ) {
33
- u := getUser (w , req )
34
+ u := getUser (req )
34
35
tpl .ExecuteTemplate (w , "index.gohtml" , u )
35
36
}
36
37
37
38
func bar (w http.ResponseWriter , req * http.Request ) {
38
- u := getUser (w , req )
39
+ u := getUser (req )
39
40
if ! alreadyLoggedIn (req ) {
40
41
http .Redirect (w , req , "/" , http .StatusSeeOther )
41
42
return
Original file line number Diff line number Diff line change @@ -2,26 +2,18 @@ package main
2
2
3
3
import (
4
4
"net/http"
5
-
6
- "github.com/satori/go.uuid"
7
5
)
8
6
9
- func getUser (w http.ResponseWriter , req * http.Request ) user {
7
+ func getUser (req * http.Request ) user {
8
+ var u user
9
+
10
10
// get cookie
11
11
c , err := req .Cookie ("session" )
12
12
if err != nil {
13
- sID , _ := uuid .NewV4 ()
14
- c = & http.Cookie {
15
- Name : "session" ,
16
- Value : sID .String (),
17
- }
18
-
13
+ return u
19
14
}
20
- //Next line may not be required, commenting it
21
- // http.SetCookie(w, c)
22
15
23
16
// if the user exists already, get user
24
- var u user
25
17
if un , ok := dbSessions [c .Value ]; ok {
26
18
u = dbUsers [un ]
27
19
}
You can’t perform that action at this time.
0 commit comments