here the simple go application. I am getting "go run: cannot run non-main package" error, if I run following code.
package zsdfsdf
import (
"fmt"
)
func Main() {
fmt.Println("sddddddd")
}
to fix it, I just need to name the package to main.but i dont 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
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:
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).The entry point of each go program is
main.main
, i.e. a function called main in a package called main. You have to provide such a main package.GAE is an exception though. They add a
main
package, containing themain
function automatically to your project. Therefore, you are not allowed to write your own.You need to use the main package, a common error starting with go is type
instead
A Solution to avoid this error is defining entry point
somefilename.go
file as main package by addingpackage main
as the first line of the entrypopin