dongqiu7365 2018-08-05 16:16
浏览 38
已采纳

如何创建本地VGO应用程序模块

Every example I've seen with vgo so far requires you to write your module, upload it then create a new application module to test a basic module.

Is there a way to test a module by skipping the repo step and just adding a package main to your module just to spit out something to the console?

I've tried creating my dummy module module "example.com/m" adding a dummy subpackage to the package example in /example/testing.go then added a simple main.go and tried importing the example package from my dummy module to no avail.

If I had no internet, I'd be pretty lost with the vgo workflow (I'm lost without it tbh)

  • 写回答

1条回答 默认 最新

  • duanqian9503 2018-09-02 16:51
    关注

    I figured it out. Basically vgo allows you to include package main in the root, but by doing this you can only use 'main' packages in the root directory of your vgo project because golang only permits one package name per folder. Which is fine since you can remove the main file later if you want.

    Answer

    • Create a package main file in the root directory of your vgo project with a fn main

    • Create any amount of sub packages in your vgo project ex.: package example in an example sub folder. For fun create an exported function that prints out "Hello World" and call it "WorldGreeting"

    • Now in your main file you can import this package by calling your module name followed by the sub package name. So for instance if your module name is bitbucket.com/User/MyVGOPackage then you would import your sub package in the main file like import "bitbucket.com/User/MyVGOPackage/example" then call your function inside of main example.WorldGreeting()
    • Build using go build to build the full directory (in case you have more main packages in the directory) and vgo will spit out an exe called "MyVGOPackage.exe"

    Tip: If you just want to create an application without a weird module name just rename your module to something simple like "MyApplication" and vgo will understand your imports perfectly. then go back and replace "bitbucket.com/User/MyVGOPackage/example" to "MyApplication/example" and everything will build normally. Jetbrain's GoLand IDE understands this usage perfectly so give it a shot if vs code is having issues auto completing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!