I wish to use Google App Engine for serve static files and REST request in one application.
I use this app.yaml
application: test
version: 1
runtime: go
api_version: go1
default_expiration: "7d 5h"
handlers:
- url: /(index.html)?
static_files: static/app/index.html
upload: static/app/index.html
http_headers:
Content-Type: text/html; charset=UTF-8
- url: /
static_dir: static/app/
http_headers:
Vary: Accept-Encoding
- url: /.*
script: _go_app
It works for static files, but I can't access to my script.
package main
import (
"fmt"
"net/http"
)
func init() {
http.HandleFunc("/hello_world", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, world!")
}
It's possible? If yes, how I can to proceed?
Yes, it's possible for an app to serve both static files and dynamic content. Actually there's nothing magical required for it, this is normal for most web applications.
Your configuration looks ok. One thing you should change: the package of your go file.
Don't use package main
, instead use another package and make sure your .go
file is put into that. For example if you name your package mypackage
, use this folder structure:
+ProjectRoot
app.yaml
+mypackage
myfile.go
And start your myfile.go
with line:
package mypackage