Go文件夹布局的问题

时间:2014-07-07 00:26:33

标签: go

我在运行Go测试时遇到问题。我跟着go instructions

.zshrc

export GOPATH=/Users/chris/Projects/go
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$GOPATH

示例app文件=> /Users/chris/Projects/go/src/github.com/chris/roundrobin

./main.go
./roundrobin.go
./roundrobin_test.go

main.go

package main

import "github.com/chris/schedule"

func main(teamCount int) {
    http.HandleFunc('/', func(w http.ResponseWriter, r, *http.Request) {
        gameSchedule := schedule.NewSchedule()
    }
}

ROUNDROBIN / schedule.go

package roundrobin

// nothing imported here for now
...

ROUNDROBIN / schedule_test.go

package roundrobin

import (
    "testing"

    "github.com/chris/roundrobin/schedule"
)
...

尝试构建(仅在主文件存在时才会失败)

我能够构建,直到我更改为github.com/username/文件夹布局

➜  roundrobin  go build
can't load package: package github.com/chris/roundrobin: found packages main (main.go) and roundrobin (schedule.go) in /Users/chris/Projects/go/src/github.com/chris/roundrobin

尝试运行测试

➜  roundrobin  go test
# github.com/chris/roundrobin
schedule_test.go:6:2: cannot find package "github.com/chris/roundrobin/schedule" in any of:
  /usr/local/go/src/pkg/github.com/chris/roundrobin/schedule (from $GOROOT)
  /Users/chris/Projects/go/src/github.com/chris/roundrobin/schedule (from $GOPATH)
FAIL    github.com/chris/roundrobin [setup failed]

有什么想法吗?

0 个答案:

没有答案