Created
February 15, 2018 07:43
-
-
Save ekoeryanto/c2a3e2b2c4a0b638a9f65987f61b6924 to your computer and use it in GitHub Desktop.
Google App Engine Static Website with Go Runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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