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 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)