去运行:不能运行非主包 [英] go run: cannot run non-main package

查看:99
本文介绍了去运行:不能运行非主包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是简单的应用程序。

  package zsdfsdf $ b我得到了go run:can not run non-main package的错误,如果我运行下面的代码。 
$ b导入(
fmt


func Main(){
fmt.Println(sdddddd)
}

解决它,我只需要命名该包到main.but但我不明白为什么我需要要做到这一点。我应该可以根据需要命名该包。另外一个问题,我知道主要功能是程序的入口点,您需要它。否则它将无法工作。但我看到一些没有主要功能的代码仍然有效。

点击此链接,页面底部的示例没有使用package main和主要功能,它仍然有效。只是好奇而已。



https://开发者.google.com / appengine / docs / go / gettingstarted / usingdatastore

解决方案

您需要在应用中指定.yaml文件你的应用访问点是什么。看一看这里。您需要指定:

  application:zsdfsdf 

另请参阅上述链接:


注意:当编写独立的Go程序中,我们将这个代码放在包main中,Go App Engine Runtime提供了一个特殊的主b $ b包,所以你应该把HTTP处理器代码放在
选项的包中(在这种情况下,


所有的Go程序都需要 Main 方法。但它是由Google App Engine提供的。这就是您提供的示例工作的原因。您的示例在本地不起作用(不在GAE上)。


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:

application: zsdfsdf

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 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).

这篇关于去运行:不能运行非主包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆