3

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

For your problem, I think there is a specific 'precompilation' command for app engine vs non-app engine described here: blog.golang.org/the-app-engine-sdk-and-workspaces-gopath
Thanks. An answer before I even posted the question. Looks like exactly what I have been looking for and not stumbled accross.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.