Skip to content

Instantly share code, notes, and snippets.

@Shaked
Created May 20, 2015 07:35
Show Gist options
  • Save Shaked/9f375f9bd389e42e96d6 to your computer and use it in GitHub Desktop.
Save Shaked/9f375f9bd389e42e96d6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/a/", func(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &http.Cookie{
Name: "shaked",
Value: "I own this",
Path: "/",
})
http.Redirect(w, r, "/b/", http.StatusFound)
})
http.HandleFunc("/b/", func(w http.ResponseWriter, r *http.Request) {
value := "empty"
c, err := r.Cookie("shaked")
if nil != err {
value = ""
log.Println(err)
} else {
value = c.Value
}
fmt.Fprintf(w, "The cookie value is: ", value)
})
log.Fatalln(http.ListenAndServe("localhost:9999", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment