Advertisement
drpanwe

Untitled

Apr 7th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. 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.
  2.  
  3. This document explains all the things the Go tool can do:
  4.  
  5. http://golang.org/cmd/go/
  6.  
  7. But I want to concentrate on this section:
  8.  
  9. http://golang.org/cmd/go/#hdr-Remote_import_path_syntax
  10.  
  11. 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:
  12.  
  13. Note: go get disables the "terminal prompt" by default. This can be changed by setting an environment variable of git:
  14.  
  15. $ export GIT_TERMINAL_PROMPT=1; go get github.com/SUSE/caaspctl
  16. --> package github.com/SUSE/caaspctl: no Go files in C:\Users\drpan\go\src\github.com\SUSE\caaspctl
  17.  
  18. Note: Windows user might get: bash: /dev/tty: No such device or address
  19. Solution: git config --global credential.helper wincred
  20.  
  21.  
  22.  
  23. We will do the rest of the work from:
  24. cd $GOPATH/src/github.com/SUSE/caaspctl
  25.  
  26.  
  27. First create a Fork (use Github UI) and then add it as remote:
  28. $ git remote add drpaneas https://github.com/drpaneas/caaspctl
  29.  
  30. 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.
  31.  
  32. Branching and Pull Requests
  33. 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:
  34.  
  35. git checkout -b fix-something
  36. git commit add -m "Fix going from A to B"
  37. git push drpaneas fix-something-with-psp
  38.  
  39. … and then easily reset master so you don’t get out of sync:
  40.  
  41. git fetch origin
  42. git reset --hard origin/master
  43. It turns out this is not too complicated after all.
  44.  
  45.  
  46. https://splice.com/blog/contributing-open-source-git-repositories-go/
  47. https://docs.google.com/document/d/1_IJTRD6dDQvyCfyim4KJexq8ZrKUPvUd3GMSA8cw8A4/edit
  48. https://thoughtbot.com/blog/contributing-to-open-source-golang-projects
  49.  
  50. Structure:
  51. https://github.com/golang-standards/project-layout/issues/1
  52.  
  53.  
  54. 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.
  55. Note: The Go path ($GOPATH) is used to resolve import statements.
  56.  
  57. Now let’s check that the tests pass. For the caaspctl project, that’s:
  58.  
  59. go test ./...
  60.  
  61. https://medium.com/golang-learn/go-project-layout-e5213cdcfaa2
  62.  
  63. https://github.com/pi-hole/pi-hole/wiki/How-to-signoff-your-commits.
  64.  
  65. https://www.reddit.com/r/golang/comments/8g26il/what_is_the_recommended_go_project_folder/
  66.  
  67.  
  68. Internal: https://docs.google.com/document/d/1e8kOo3r51b2BWtTs_1uADIA5djfXhPT36s6eHVRIvaU/edit
  69. Internal package
  70. Naming your package as internal, hides your package’s internals even more, brings more encapsulation.
  71. 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.
  72.  
  73. Internal package is used to make specific packages unimportable.
  74.  
  75. https://blog.learngoprogramming.com/definitive-guide-to-go-packages-focus-on-the-fundamentals-to-empower-your-skills-d14aae7cd321
  76.  
  77. https://www.reddit.com/r/golang/comments/9dqrwm/newbie_question_re_folder_structure/
  78.  
  79. 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