我正在从
github.com/tarm/serial
案例1:如果将上述回购签入
$GOPATH/src/github.com/tarm/serial
案例2:如果回购在
$GOPATH/src/vendor/github.com/tarm/serial
这个
go build
指挥部会抱怨的
cannot find package "github.com/tarm/serial
案例3:The
other SO answers
./vendor
所以包裹在
./vendor/github.com/tarm/serial
. 那也不行。
细节:
失败的命令
gotester:~/testdir$ go build uarttest_main.go
uarttest_main.go:5:9: cannot find package "github.com/tarm/serial" in any of:
/home/gotester/bin/go/src/github.com/tarm/serial (from $GOROOT)
/home/gotester/testdir/libs/src/github.com/tarm/serial (from $GOPATH)
源代码位于
./
:
gotester:~/testdir$ cat uarttest_main.go
package main
import (
"log"
"github.com/tarm/serial"
)
func main() {
c := &serial.Config{Name: "COM45", Baud: 115200}
s, err := serial.OpenPort(c)
if err != nil {
log.Fatal(err)
}
n, err := s.Write([]byte("test"))
if err != nil {
log.Fatal(err)
}
buf := make([]byte, 128)
n, err = s.Read(buf)
if err != nil {
log.Fatal(err)
}
log.Printf("%q", buf[:n])
}
供应商
目录:
gotester:~/testdir$ tree --charset=ascii ./vendor
./vendor
`-- github.com
`-- tarm
`-- serial
|-- basic_test.go
|-- LICENSE
|-- README.md
|-- serial.go
|-- serial_linux.go
|-- serial_posix.go
`-- serial_windows.go
3 directories, 7 files
如果现在运行此命令:
mv ./vendor/github.com ./libs/src
,生成将成功。