Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7797491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:42:03+00:00 2026-06-01T23:42:03+00:00

I am having trouble understanding the workflow for creating a go project that has

  • 0

I am having trouble understanding the workflow for creating a go project that has local packages.

Say I create a new project, using git for version control, which has a main.go file and a tools.go file which will be in package utils. So I have a directory structure such as this:

/myproject/
   main.go
   utils/
     tools.go

main.go looks like this:

package main
import "./utils"
func main() {
    utils.DoSomthing()
}

and tools.go looks like this:

package utils;
func DoSomething() {
}

Everything works just fine locally, using go build and go run. But this is being hosted on github, and I’d like to be able to have others use the go get command to install it. So the local package import must be changed to use the format “github.com/user/project/utils”, which works, except now I have two copies of the source code, and the real problem is that the copy with the git history has an import that makes use of the downloaded copy. So if I’m working on the copy with the git history, any changes made to tools.go will go unnoticed, because it will be using the downloaded copy.

So I’m wondering if someone can explain the right way of using go get, version control, and package imports within the same project.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:42:05+00:00Added an answer on June 1, 2026 at 11:42 pm

    I’ve just written a short step-by-step guide on how I am using the new go tool and github.com. You might find it useful:

    1. Setup your GOPATH

    You can set the environment variable GOPATH to any directory you like. If you have larger projects, it’s probably a good idea to create a different GOPATH for each of them. I would recommend this approach especially for the deployment, so that updating a library for project A doesn’t break project B which might require an earlier version of the very same library.

    Also note that you can set your GOPATH to a list of directories, delimited by colons. So you might have a GOPATH containing all commonly used packages, and separate GOPATHS for each project with additonal packages or different versions of existing packages.

    But unless your are working on a lot of different Go projects simultaneously, its probably enough to have just a single GOPATH locally. So, let’s create one:

    mkdir $HOME/gopath
    

    Then you need to set two environment variables to tell the go tool where it can find existing Go packages and where it should install new ones. It’s probably best to add the following two lines to your ~/.bashrc or ~/.profile (and do not forget to reload your .bashrc afterwards).

    export GOPATH="$HOME/gopath"
    export PATH="$GOPATH/bin:$PATH"
    

    2. Create a new project

    If you want to create a new Go project which should be hosted at github.com later, you should create this project under $GOPATH/src/github.com/myname/myproject. It’s important that the path matches the URL of the github.com repo, because the go tool will follow the same convention. So, let’s create the project root and initialize a new git repository there:

    mkdir -p $GOPATH/src/github.com/myname/myproject
    cd $GOPATH/src/github.com/myname/myproject
    git init
    

    Because I do not like to type such long paths, I normally create symbolic links for the projects I am currently working on in my home folder:

    ln -s $GOPATH/src/github.com/myname/myproject ~/myproject
    

    3. Write your application

    Start coding and don’t forget to git add and git commit your files. Also, do not use relative imports like import "./utils" for sub-packages. They are currently undocumented and shouldn’t be used at all, because they won’t work with the go tool. Use imports like github.com/myname/myproject/utils instead.

    4. Publish your project

    Create a new repository at github.com, upload your SSH public key if you haven’t done that before and push your changes to the remote repository:

    git remote add origin git@github.com:myname/myproject.git
    git push origin master
    

    5. Continue working on your project

    If you have set the GOPATH in your .bashrc and if you have created a symlink to your project in your home folder, you can just type cd myproject/ and edit some files there. Afterwards, you can commit the changes using git commit -a and send them to github.com by doing a git push.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from here Im having trouble understanding they say that ado.net does not include a
I am having trouble understanding how escaping works inside html tag attribute values that
I am having trouble understanding the difference between these two commands that in my
I'm having trouble understanding how compilers and linkers work and the files they create.
I'm having trouble understanding how QGraphicsItemAnimation's setScaleAt function works. Here's the code I'm using:
I'm having trouble understanding how to use ORM generated objects. We're using LLBLGen for
I'm having trouble understanding the following bit of code that I was hoping would
I'm having trouble understanding how a git merge works in terms of the commits
I'm having trouble understanding why Python raises a TypeError when you provide arguments that
I'm having trouble understanding the for/in statement in JavaScript. The book which I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.