我正在使用带有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
我不明白此错误消息:没有包含该文件的软件包吗?