Golang relative package import after renaming

后端 未结 1 704
难免孤独
难免孤独 2021-01-21 12:27

My $GOPATH is

\"/Users/peter/goworkspace\"

My current golang version:

go version go1.6 darwin/amd64

I have m

相关标签:
1条回答
  • 2021-01-21 12:56

    Rule #1: Don't use relative imports. This is (partly) why you're running into issues. Read through this: https://golang.org/doc/code.html#Library

    Use the fully qualified import paths (as you showed):

    import(
        "project1/package1"  
        "project1/package2"   
        "project1/package3"
        // Or ideally, so others can access it in the future:
        "github.com/<yourusername>/project1/package4"
    )  
    

    If for some reason you want to version your package, you can either:

    • Provide a new repository (import URL)
    • Use a service like gopkg.in (http://labix.org/gopkg.in) to provide versioned import URLs (e.g. gopkg.in/you/pkgname.v2)
    0 讨论(0)
提交回复
热议问题