Skip to content

Instantly share code, notes, and snippets.

@tatsuyasusukida
Last active August 1, 2022 06:26
Show Gist options
  • Save tatsuyasusukida/99b67b327f836fd531bee7e8211e702d to your computer and use it in GitHub Desktop.
Save tatsuyasusukida/99b67b327f836fd531bee7e8211e702d to your computer and use it in GitHub Desktop.
Cloud Run golang redirect server
module loremipsum.co.jp/redirect
go 1.18
package main
import (
"log"
"net/http"
"os"
)
func main () {
location := os.Getenv("LOCATION")
if location == "" {
log.Fatal("location == \"\"")
}
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
w.Header().Set("Location", location)
w.WriteHeader(http.StatusMovedPermanently)
})
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
log.Printf("Listening on %s\n", port)
log.Fatal(http.ListenAndServe(":" + port, nil))
}
all:
deploy:
source .env && gcloud run deploy $$SERVICE \
--source . \
--region asia-northeast1 \
--platform managed \
--allow-unauthenticated
gist:
source .env && gist -u $$GIST_ID \
-od "Cloud Run golang redirect server" \
go.mod main.go makefile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment