Skip to content

Instantly share code, notes, and snippets.

@treeder
Last active April 27, 2018 20:34
Show Gist options
  • Save treeder/8115c12dbc147a06b290 to your computer and use it in GitHub Desktop.
Save treeder/8115c12dbc147a06b290 to your computer and use it in GitHub Desktop.
Serving static site on app engine with golang

Put all your static files in /static directory. If you put index.html into /static, it will be served up as welcome file.

application: helloworld
version: 1
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
package hello
import (
"fmt"
"net/http"
)
func init() {
http.HandleFunc("/ping", ping)
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "static/"+r.URL.Path)
}
func ping(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "pong")
}
@patjackson52
Copy link

Using this approach will not use CDN and the benefits associated with it - faster response, less traffic on your instances

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment