Forcing a Specific Import Path in Go

后端 未结 1 1260
死守一世寂寞
死守一世寂寞 2021-01-19 19:04

New Go programmer here -- apologies if this is well worn territory, but my google searching hasn\'t turned up the answer I\'m looking for.

Short Version: Can I, as

相关标签:
1条回答
  • 2021-01-19 19:24

    Yes it's built in, I can't seem to find the implementation document (it's a relatively new feature in 1.5 or 1.6) however the syntax is:

    package name // import "your-custom-path"
    

    Example: https://github.com/golang/crypto/blob/master/bcrypt/bcrypt.go#L7

    // edit

    The design document for this feature is https://docs.google.com/document/d/1jVFkZTcYbNLaTxXD9OcGfn7vYv5hWtPx9--lTx1gPMs/edit

    // edit

    @JimB pointed out to https://golang.org/cmd/go/#hdr-Import_path_checking, and in the go1.4 release notes: https://golang.org/doc/go1.4#canonicalimports

    0 讨论(0)
提交回复
热议问题