debuggoModerate
go run: cannot run non-main package
Viewed 0 times
runpackagemainnoncannot
Problem
here the simple go application. I am getting "go run: cannot run non-main package" error, if I run following code.
To fix it, I just need to name the package to
Another question, I know main function is the entry point of the program, you need it. otherwise it will not work. But I see some codes that didn't have main function still works.
Click on this link, the example at the bottom of the page didn't use package main and main function, and it still works. just curious why.
https://developers.google.com/appengine/docs/go/gettingstarted/usingdatastore
package zsdfsdf
import (
"fmt"
)
func Main() {
fmt.Println("sddddddd")
}To fix it, I just need to name the package to
main. But I don't understand why I need to do that. I should be able to name the package whatever I want.Another question, I know main function is the entry point of the program, you need it. otherwise it will not work. But I see some codes that didn't have main function still works.
Click on this link, the example at the bottom of the page didn't use package main and main function, and it still works. just curious why.
https://developers.google.com/appengine/docs/go/gettingstarted/usingdatastore
Solution
You need to specify in your app.yaml file what your app access point is. Take a look here. You need to specify:
Also see from that above link:
"Note: When writing a stand-alone Go program we would place this code
in package main. The Go App Engine Runtime provides a special main
package, so you should put HTTP handler code in a package of your
choice (in this case, hello)."
You are correct that all Go programs need the
application: zsdfsdfAlso see from that above link:
"Note: When writing a stand-alone Go program we would place this code
in package main. The Go App Engine Runtime provides a special main
package, so you should put HTTP handler code in a package of your
choice (in this case, hello)."
You are correct that all Go programs need the
Main method. But it is provided by Google App Engine. That is why your provided example works. Your example would not work locally (not on GAE).Code Snippets
application: zsdfsdfContext
Stack Overflow Q#23870801, score: 27
Revisions (0)
No revisions yet.