douqi0090 2019-02-15 20:08
浏览 102

如何使用go mod复制非执行文件

go mod does not include the non-go code in the vendor directory.

Currently we are using go with go-oracle to connect to the database. We are planning on using docker so went with the idea of using go modules to version-ize our project. But since go-oracle has sub folders which have C code, it does not get copied over from the mod directory that go creates in the pkg folder. Is there a way we could add the non go code as well? We did try to use https://github.com/goware/modvendor but it did not copy the non-go code. Unless we did not use it correctly.

package main

import (
  "fmt"

  "github.com/jmoiron/sqlx"
  log "github.com/sirupsen/logrus"
  goracle "gopkg.in/goracle.v2"
)

const connectionString = "some connection string"

func main() {
  fmt.Print("Inside main")
  db, err := sqlx.Connect("goracle", connectionString)
  if err != nil {
    log.Infof("Could not connect %v%", err)
  } else {
    db.Query("select 1 from dual")
  }

  fmt.Println(goracle.DriverName)
}

go mod init go mod vendor

You will see that the code will not compile.

  • 写回答

1条回答 默认 最新

  • doupi4649 2019-02-15 20:43
    关注

    I believe your issue is that you did not set a module path for your package. Details on my actions to build your code below:

    After creating a test package gomod-test in my /tmp folder, I ran:

    go mod init tmp/gomod-test // <-- this is the module path
    go mod vendor
    

    which pulled in the required dependencies including gopkg.in/goracle.v2 inside of ./vendor/goracle.v2/. I was then able to build the "project" using

    go build main.go
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程