Skip to content

Instantly share code, notes, and snippets.

@ekoeryanto
Created February 15, 2018 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekoeryanto/c2a3e2b2c4a0b638a9f65987f61b6924 to your computer and use it in GitHub Desktop.
Save ekoeryanto/c2a3e2b2c4a0b638a9f65987f61b6924 to your computer and use it in GitHub Desktop.
Google App Engine Static Website with Go Runtime
runtime: go
api_version: go1
threadsafe: yes
handlers:
- url: /.well-known/.*
script: _go_app
- url: /.*
script: _go_app
secure: always
redirect_http_response_code: 301
package main
import (
"net/http"
)
func init() {
http.Handle("/", http.FileServer(http.Dir("public")))
http.HandleFunc("/.well-known/", LetsEncryptHandler)
}
func LetsEncryptHandler(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
key := strings.Split(r.URL.Path, "/")[3]
ctx.Infof("%s", key)
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
if item, err := memcache.Get(ctx, key); err == memcache.ErrCacheMiss {
ctx.Infof("item not in the cache")
} else if err != nil {
ctx.Errorf("error getting item: %v", err)
} else {
ctx.Infof("the challenge is %q", item.Value)
challenge := string(item.Value)
w.Write([]byte(challenge))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment