V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
tinyRat
V2EX  ›  问与答

GoPATH 如何迁移到 GoMod

  •  
  •   tinyRat · Jun 25, 2021 · 1795 views
    This topic created in 1768 days ago, the information mentioned may be changed or developed.

    之前的项目用的是 GoPath 来组织代码结构的,现在准备迁移至 GoMod 。

    遇到一个问题是,代码中包的引用太多,对于项目中的包有比较好的工具进行批量修改嘛?

    比如:

    使用 GoPath 引入项目内 config 包:

    import "config"
    

    转用 GoMod 后,需要修改为:

    import "xxx.com/config"
    

    请问下大家,有比较好的方式嘛?

    4 replies    2021-06-25 12:54:24 +08:00
    kxjhlele
        1
    kxjhlele  
       Jun 25, 2021
    该一下 go.mod 就好了呀
    tinyRat
        2
    tinyRat  
    OP
       Jun 25, 2021
    @kxjhlele

    但是项目内的包引用有工具批量修改嘛?

    比如使用 GoPath 的项目结构如下:

    ```text
    .
    └── src
    ├── config
    │   └── config.go
    ├── go.mod
    └── main.go
    ```

    ```text
    > cat src/main.go
    package main

    import "config"

    func main() {
    config.LoadConfig()
    }
    ```

    使用 `go mod init` 之后,需要手动修改 `config` 包路径。
    zdt3476
        3
    zdt3476  
       Jun 25, 2021
    这个没啥好办法,只能批量改。全局搜索 "config" 替换成 "xxx.com/config",我当初就是这么改的,带引号基本不会匹配到其他不合适的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3542 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 11:22 · PVG 19:22 · LAX 04:22 · JFK 07:22
    ♥ Do have faith in what you're doing.