My GOPATH is $HOME/go
, I put my project's source code in $HOME/go/src/myproj
and there are two files:
app.yaml:
application: hello
version: 1
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
and hello.go
package hello
import (
"net/http"
"github.com/gin-gonic/gin"
)
func ping(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
}
func init() {
r := gin.Default()
api := r.Group("/api")
{
api.GET("/ping", ping)
}
http.Handle("/", r)
}
Then I run dev_appserver.py .
It works,
curl http://127.0.0.1:8080/api/ping
{"message":"pong"}
Then I decide to split hello.go this way:
new hello.go
package hello
import (
"net/http"
"github.com/gin-gonic/gin"
"./api"
// "myproj/api" // does not work too
)
func init() {
r := gin.Default()
api.addRoute()
http.Handle("/", r)
}
and a api
folder, and api/api.go
file
package api
import (
"github.com/gin-gonic/gin"
)
func ping(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
}
func addRoute() {
api := r.Group("/api")
{
api.GET("/ping", ping)
}
}
Then I run dev_appserver.py .
again but got this error:
ERROR 2018-09-28 05:17:47,653 instance_factory.py:229] Failed to build Go application: (Executed command: /Users/gaco/.google-cloud-sdk/platform/google_appengine/goroot-1.9/bin/go-app-builder -app_base /Users/gaco/go/src/myproj -api_version go1 -arch 6 -dynamic -goroot /Users/gaco/.google-cloud-sdk/platform/google_appengine/goroot-1.9 -nobuild_files ^^$ -incremental_rebuild -unsafe -print_extras_hash hello.go api/api.go)
2018/09/28 14:17:47 go-app-builder: Failed parsing input: app file api.go conflicts with same file imported from GOPATH
WARNING 2018-09-28 05:17:47,654 instance.py:297] Could not get PID of instance ERROR 2018-09-28 05:17:47,654 instance.py:300] '_GoBuildFailureRuntimeProxy' object has no attribute '_process'
What is the problem? How can I solve it?