导入路径无效 - Go + windows

时间:2017-07-26 10:05:47

标签: windows go import

尝试从Windows文件系统导入文件时:

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

我收到此错误

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

我已检查$PATH环境变量包含github.com的目录,$GOROOT也设置为指向Go安装。

我认为它与文件路径本身有关,但我无法找到有关如何在Windows环境中执行文件路径的任何信息。

由于

1 个答案:

答案 0 :(得分:3)

您必须在导入路径(导入声明)中使用正斜杠/,即使您在Windows上也是如此。

Spec: Import declarations:

  

实现限制:编译器可以仅使用属于Unicode's L,M,N,P和S一般类别(不带空格的图形字符)的字符将ImportPaths限制为非空字符串,并且可以还排除字符!"#$%&'()*,:;<=>?[\]^ {|}`和Unicode替换字符U + FFFD

任何编译器都可以排除反斜杠\字符。即使您使用的也不是,但您的代码将无法移植。

所以请尝试:

import (
    pb "github.com/sewelol/sgx-decryption-service/decryptionservice"
    dev "github.com/sewelol/sgx-decryption-service/device"
    "google.golang.org/rpc"
)
相关问题