Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The get command will download code, build and install packages and produce an executable binary if you are building a program. It is very smart and can read your code to find dependencies that it will download, built and install as well. That is, if everything is structured and set correctly.
- This document explains all the things the Go tool can do:
- http://golang.org/cmd/go/
- But I want to concentrate on this section:
- http://golang.org/cmd/go/#hdr-Remote_import_path_syntax
- It is very important to stay close to what 'go get' does. If you start cloning whenever and changing the GOPATH, then go fuck yourself and find the solution on your own. So, we are going to stick to the 'go tool' way of doing things:
- Note: go get disables the "terminal prompt" by default. This can be changed by setting an environment variable of git:
- $ export GIT_TERMINAL_PROMPT=1; go get github.com/SUSE/caaspctl
- --> package github.com/SUSE/caaspctl: no Go files in C:\Users\drpan\go\src\github.com\SUSE\caaspctl
- Note: Windows user might get: bash: /dev/tty: No such device or address
- Solution: git config --global credential.helper wincred
- We will do the rest of the work from:
- cd $GOPATH/src/github.com/SUSE/caaspctl
- First create a Fork (use Github UI) and then add it as remote:
- $ git remote add drpaneas https://github.com/drpaneas/caaspctl
- It’s important to fork the project and use the git remote in this way, instead of forking and cloning into another location, so that the project’s import statements still work.
- Branching and Pull Requests
- Assuming that the SUSE/caaspctl repo is at origin, and your fork is at drpaneas, you can use all the usual branching shenanigans for creating a pull request:
- git checkout -b fix-something
- git commit add -m "Fix going from A to B"
- git push drpaneas fix-something-with-psp
- … and then easily reset master so you don’t get out of sync:
- git fetch origin
- git reset --hard origin/master
- It turns out this is not too complicated after all.
- https://splice.com/blog/contributing-open-source-git-repositories-go/
- https://docs.google.com/document/d/1_IJTRD6dDQvyCfyim4KJexq8ZrKUPvUd3GMSA8cw8A4/edit
- https://thoughtbot.com/blog/contributing-to-open-source-golang-projects
- Structure:
- https://github.com/golang-standards/project-layout/issues/1
- The statement import "github.com/stretchr/testify/assert" doesn't mean that the package is directly imported from github website (through http). It's imported from your local, from github.com/stretchr/testify path under $GOPATH/src. The package was downloaded and stored there before, so it can be imported into any project.
- Note: The Go path ($GOPATH) is used to resolve import statements.
- Now let’s check that the tests pass. For the caaspctl project, that’s:
- go test ./...
- https://medium.com/golang-learn/go-project-layout-e5213cdcfaa2
- https://github.com/pi-hole/pi-hole/wiki/How-to-signoff-your-commits.
- https://www.reddit.com/r/golang/comments/8g26il/what_is_the_recommended_go_project_folder/
- Internal: https://docs.google.com/document/d/1e8kOo3r51b2BWtTs_1uADIA5djfXhPT36s6eHVRIvaU/edit
- Internal package
- Naming your package as internal, hides your package’s internals even more, brings more encapsulation.
- When you name a package as internal, it can only be imported from its parent directory’s packages. If you put into deeper sub-folders, one-step up, its parent packages can access it.
- Internal package is used to make specific packages unimportable.
- https://blog.learngoprogramming.com/definitive-guide-to-go-packages-focus-on-the-fundamentals-to-empower-your-skills-d14aae7cd321
- https://www.reddit.com/r/golang/comments/9dqrwm/newbie_question_re_folder_structure/
- https://dave.cheney.net/2014/12/01/five-suggestions-for-setting-up-a-go-project
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement