Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structure for your go workspace when using private git repository

Tags:

go

Ive been trying to work out what the standard folder layout/structure for go code/workspaces when you are not using github.

I can see how go get works when fetching github projects, but assumedly my own git projects would not have the {github.com}/{username}/{projectname} structure that is referenced by go get and how is structed on disk after you do go get

What layout and git get url should you have when using your own git private repositories?

like image 467
Jay Avatar asked May 22 '14 12:05

Jay


People also ask

What is the difference between workspace and repository?

Think of the red Workspace box in the first diagram as a moving box. Originally, it is on top of the Repository box when you do a git clone because there is no difference between the two. Think of the Repository as a Safe/Lock Box where you keep valuables. It only gets updated when you commit changes to it.

What is the main focus of the private Git repository?

Our main focus is on the private git repository. Modules have greatly improved the code maintainability in go. It is dependency management in go Lang just like Maven in Java applications. If you are new to modules in go please click here for official documentation. In Java, an artifact is maintained in a repository like Nexus.

Is your GitHub repository secure?

Fortunately, GitHub has an active security team, and recently, they revealed a Trojan that had been committed into several Git repositories, having snuck past even the repo owners. While we can’t control how other people manage their own repositories, we can learn from their mistakes.

Where does my code go when I commit to a repository?

It is in your workspace.we normally do is, we add to indexes and commit to the repository, then your code gonna save to your repository. I like to give you one tip for you. when you learning the git, always use the git bash tool.


2 Answers

The package in itself carries no reference to where it is stored. You only have:

package mypackage

So, you can have your local version in your own structure, as Volker pointed out in his comment. This is the import path you use in your own projects:

import "my/custom/path/mypackage"

Then you can open source it and put mypackage onto GitHub. This will allow everyone else to get it with the go get command, but they will be using the github.com import:

import "github.com/myuser/mypackage"

This works perfectly fine unless you want to open-source packages which imports my/custom/path/mypackage. In such a case, you should consider restructuring your paths so that you use the same github import paths as the users of your package does.

like image 70
ANisus Avatar answered Oct 02 '22 15:10

ANisus


From go help importpath:

For code hosted on other servers, import paths may either be qualified with the version control type, or the go tool can dynamically fetch the import path over https/http and discover where the code resides from a tag in the HTML.

To declare the code location, an import path of the form

repository.vcs/path

specifies the given repository, with or without the .vcs suffix, using the named version control system, and then the path inside that repository. The supported version control systems are:

Bazaar .bzr Git .git Mercurial .hg Subversion .svn

Then I belive you can setup your own git server with GitLab or GoGits, then your import path will be your server domain.

But If you have a private repo with github or bitbucket, your package will go-get-able. Just run a normal "go get" and you will asked to enter your password.

like image 22
nvcnvn Avatar answered Oct 02 '22 13:10

nvcnvn