如何使用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.

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