dongzhong8834 2013-09-12 22:20
浏览 24

导入前缀golang?

From what I understand, golang imports modules like

import (
  "bitbucket.org/user/project"
  "github.com/user/project"
)

is there a way to import modules in all files, without explicitly typing an absolute remote location out, from

1) a single remote location?

2) multiple locations?

So for 1), you could specify somewhere that the host is github.com/user and any import that is not a default library and doesn't have a remote prefix is prefixed by github.com/user. Or have a prefix_variable + relative/path and be able to set the prefix_variable somewhere?

So like

// in some config file
github = "github.com/user/"
bitbucket = "bitbucket.org/user/"

// imported in file
import ( 
  bitbucket + "project" // "bitbucket.org/user/project"
  github + "project" // "github.com/user/project"
)

or

// in some config file 
default = "github.com/user"

// imported in file
import (
  "bitbucket.org/user/project"  // this has a remote prefix, so default prefix is not added
  "project" // "github.com/user/project"
)
  • 写回答

1条回答 默认 最新

  • duanniying2342 2013-09-12 23:04
    关注

    Unfortunately to my knowledge there is no way to do this in the way you have stated. There is a discussion in Google Go Group which is somewhat related Go Packaging: building a great packaging story which might give you some ideas of the thought process for why this cant be done (assuming you were not aware of this already).

    I actually have a related problem which is associated with producing a build for two different server environments, one for Google App Engine and one for a local linux development environment sharing packages (imports) and I am still looking for the solution, hence watching this type of discussion.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值