Skip to content

Instantly share code, notes, and snippets.

@mmurray
Created September 2, 2014 20:02
Show Gist options
  • Save mmurray/1b221cc24aaa987e7419 to your computer and use it in GitHub Desktop.
Save mmurray/1b221cc24aaa987e7419 to your computer and use it in GitHub Desktop.
Go example
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