Created
September 2, 2014 20:02
-
-
Save mmurray/1b221cc24aaa987e7419 to your computer and use it in GitHub Desktop.
Go example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"fmt" | |
"http" | |
"strconv" | |
) | |
func getUserId(r *http.Request) (int64, error) { | |
c, err := r.Cookie("uid") | |
if err != nil { | |
return 0, err | |
} | |
i, err := strconv.ParseInt(c.Value, 10, 64) | |
if err != nil { | |
return 0, err | |
} | |
if i <= 0 { | |
return 0, fmt.Errorf("invalid user id") | |
} | |
return i, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment