【发布时间】:2012-09-06 18:31:52
【问题描述】:
我是第一次使用 Google GO。我已经扩展了“hello world”应用程序以尝试在 init 部分中定义路径。这是我到目前为止所做的:
package hello
import (
"fmt"
"net/http"
)
func init() {
http.HandleFunc("/service", serviceHandler)
http.HandleFunc("/site", siteHandler)
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, there")
}
func serviceHandler( w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "this is Services")
}
func siteHandler( w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "this is Sites")
}
只有handler() 回调被执行——其他的被忽略。例如:http://myserver/service/foo 打印 Hello, there。我曾希望它是this is Services。
有没有更好的方法来进行服务路由?理想情况下,无论如何我都希望这些是单独的脚本,但看起来 Go 只有一个脚本,因为 app.yaml 需要在脚本声明中使用特殊字符串 _go_app。
谢谢!
【问题讨论】:
-
Go 没有脚本。它是一种编译语言。
-
技术上,所有语言都被编译。但是,我们离题了。
标签: google-app-engine go