Go module init without VCS/Git fails with cannot determine module path

前端 未结 1 1446
一整个雨季
一整个雨季 2021-02-05 06:35

I\'m trying to initialize a new go project with go module (using go 1.11). I don\'t plan to publish it in github or elsewhere, it is just a temporary/test project with only main

相关标签:
1条回答
  • 2021-02-05 07:12

    Is it not possible to init module without using git (or other VCS)? Or is there any workaround?

    Yes, it is possible to init the modules without using VSC, initializing the module does not have to do anything with git or any other VCS.

    This error occurs when the module name is not entered while init the module so to generate a module modulename write this command.

    $ go mod init modulename
    

    The content of the go.mod would be

    module modulename
    

    EDIT:

    To use the modules from local repository use the replace directive

    In your main module where you are checking your local module add the following lines

    replace "X" v0.0.0 => "{location To your local module}"
    require "X" v0.0.0
    

    And then in your main project, import package util from module X you can simply do:

    import "X/util"
    

    Now when you will do go build it will look for this local module on the location you have given in the mod file of the main project.

    For more explanation

    0 讨论(0)
提交回复
热议问题