Skip to content

Instantly share code, notes, and snippets.

@mkmik
Created January 19, 2015 17:34
Show Gist options
  • Save mkmik/fc6f2ae457b470e3d72f to your computer and use it in GitHub Desktop.
Save mkmik/fc6f2ae457b470e3d72f to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"strings"
"time"
)
func handler(w http.ResponseWriter, r *http.Request) {
token := r.FormValue("token")
expire := time.Now().AddDate(0, 0, 1)
cookie := http.Cookie{
Name: "user-id",
Value: token,
Path: "/",
Domain: strings.Split(r.Host, ":")[0],
Expires: expire,
MaxAge: 86400,
Secure: true,
HttpOnly: true,
}
http.SetCookie(w, &cookie)
http.Redirect(w, r, "Temporary redirect", http.StatusTemporaryRedirect)
}
func main() {
http.HandleFunc("/auth", handler)
http.ListenAndServe(":8085", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment