dty97501 2017-07-26 10:05
浏览 1711
已采纳

无效的导入路径-Go + Windows

When attempting to import to files from the windows file system:

import (
    pb "github.com\\sewelol\\sgx-decryption-service\\decryptionservice"
    dev "github.com\\sewelol\\sgx-decryption-service\\device"
    "google.golang.org\pc"`
)

I get this error

server\main.go:10:5: invalid import path: "github.com\\sewelol\\sgx-decryption-service\\decryptionservice"

I have checked $PATH enviroment variable includes the directory that has github.com, and $GOROOT also is set up to point to the Go installation.

I assume it is something to do with the file paths themselves, but I can't find any information on how to do filepaths in the windows environment.

Thanks

  • 写回答

1条回答 默认 最新

  • duanhuan1147 2017-07-26 10:07
    关注

    You have to use forward slashes / in import paths (of import declarations), even if you're on Windows.

    Spec: Import declarations:

    Implementation restriction: A compiler may restrict ImportPaths to non-empty strings using only characters belonging to Unicode's L, M, N, P, and S general categories (the Graphic characters without spaces) and may also exclude the characters !"#$%&'()*,:;<=>?[\]^{|}` and the Unicode replacement character U+FFFD.

    Any compiler may exclude the backslash \ character among others. Even if you would use one that doesn't, your code would not be portable.

    So instead try:

    import (
        pb "github.com/sewelol/sgx-decryption-service/decryptionservice"
        dev "github.com/sewelol/sgx-decryption-service/device"
        "google.golang.org/rpc"
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看