作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用带有Go扩展名的VS Code,但是我注意到当我右键单击某个方法并选择“转到定义”时,找不到任何定义。例如,
这是在我使用Cobra生成的示例应用程序中:
cobra init myCobraApp --pkg-name=github.com/khpeek/myCobraApp
myCobraApp
目录的组织方式如下
.
├── LICENSE
├── cmd
│ └── root.go
└── main.go
cmd/root.go
包含在哪里
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)
var cfgFile string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "myCobraApp",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
godef
,但收到以下错误消息:
~/g/s/g/k/myCobraApp> godef -f main.go "cmd.Execute()"
godef: There must be at least one package that contains the file
最佳答案
事实证明,通过将GO111MODULE
环境变量设置为on
破坏了此功能。当我删除它时,“转到定义”按钮再次起作用。
关于go - “godef: There must be at least one package that contains the file”即使该文件确实具有包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58087134/
我是一名优秀的程序员,十分优秀!