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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)