英文:
Invalid import path - Go + windows
问题
尝试从Windows文件系统导入文件时,遇到了以下错误:
server\main.go:10:5: invalid import path: "github.com\\sewelol\\sgx-decryption-service\\decryptionservice"
我已经检查了$PATH
环境变量,确保其中包含了包含github.com
的目录,并且$GOROOT
也已经设置为指向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\\rpc"`
)
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
得分: 4
你必须在导入路径(导入声明中)使用正斜杠/
,即使你在Windows上。
实现限制:编译器可以限制ImportPaths为非空字符串,仅使用属于Unicode的 L、M、N、P和S通用类别的字符(没有空格的图形字符),还可以排除字符
!"#$%&'()*,:;<>?[\]^{|}
和Unicode替换字符U+FFFD。
任何编译器都可以排除反斜杠\
字符等其他字符。即使你使用的编译器不排除反斜杠字符,你的代码也不具备可移植性。
所以,你可以尝试这样写:
import (
pb "github.com/sewelol/sgx-decryption-service/decryptionservice"
dev "github.com/sewelol/sgx-decryption-service/device"
"google.golang.org/rpc"
)
英文:
You have to use forward slashes /
in import paths (of import declarations), even if you're on Windows.
> 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"
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论