How do you import relative module paths in windows for golang?

huangapple go评论94阅读模式
英文:

How do you import relative module paths in windows for golang?

问题

我正在尝试使用Go/App Engine编写一个Web应用程序,我的开发机器是Windows。当我尝试将我的应用程序分解为模块(main、models等),并尝试使用相对路径导入时,例如:

import './models'

我收到一个错误,说路径中的':'是非法字符。Windows使用Drive:\Path语法表示路径,而Go语言团队似乎拒绝将':'添加到允许的Go路径字符集中。

在Windows上如何编写多模块应用程序?

英文:

I'm trying to write a webapp with Go/App Engine and I'm using windows for my dev machine. When I try to break my app into modules (main, models, ...), and try to use relative path imports like

import './models'

I get an error saying that ':' is an illegal character in path. Windows uses Drive:\Path syntax for path, and the golang team seem to have refused to add ':' to the set of allowed characters in go path.

How do I write multi-module applications with Go on windows?

答案1

得分: 2

如何在Windows上使用相对模块路径导入Golang?

最简单的答案是不要使用相对路径。这些路径在长期使用中会给你带来麻烦,并且通常是不被推荐的。它们只在非常特殊的情况下使用。

如何在Windows上编写多模块应用程序?

如果你要编写多模块项目,你需要设置你的GOPATH。这可能一开始会有些麻烦,但它将使你的代码可以通过go get进行获取。

除非你在GOPATH中工作(如供应商),否则你无法使用Go的许多功能。

英文:

> How do you import relative module paths in windows for golang?

The simplest answer is don't use relative paths. These will cause you trouble in the long run and are frowned upon in general. The are only used is very special cases normally.

> How do I write multi-module applications with Go on windows?

You need to set your GOPATH if you are writing multi module projects.

It seems like a pain at first, but it will enable your code to be go get-able if you want.

You can't use quite a few features of Go unless you are working in a GOPATH (like vendoring).

huangapple
  • 本文由 发表于 2017年1月8日 22:44:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/41533906.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定