Skip to content

Instantly share code, notes, and snippets.

@adyatlov
Created May 4, 2019 11:25
Show Gist options
  • Save adyatlov/076ab0b92ed4592230a42921480ec78d to your computer and use it in GitHub Desktop.
Save adyatlov/076ab0b92ed4592230a42921480ec78d to your computer and use it in GitHub Desktop.
package main
import (
"io"
"log"
"net/http"
)
func main() {
rootHandler := func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Location", "http://localhost:8080/hello")
cookie := http.Cookie{
Name: "auth-token",
Value: "I love you",
MaxAge: 0,
Secure: false,
HttpOnly: false,
SameSite: http.SameSiteDefaultMode,
}
http.SetCookie(w, &cookie)
w.WriteHeader(http.StatusTemporaryRedirect)
}
http.HandleFunc("/", rootHandler)
helloHandler := func(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "Hello, world!\n")
}
http.HandleFunc("/hello", helloHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment