Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HOME, GOPATH and me

Yoji Shidara
January 21, 2015

HOME, GOPATH and me

Sapporo #golang Meetup
2015-01-21

Yoji Shidara

January 21, 2015
Tweet

More Decks by Yoji Shidara

Other Decks in Technology

Transcript

  1. )0.&ͱ(01"5)ͱࢲ
 —HOME, GOPATH and me ઃᒜ༸࣐
 !EBSBTIJ Sapporo #golang Meetup


    2015-01-21 5IFNBTDPUXBTEFTJHOFECZ3FOÉF'SFODI
 -JDFOTFEVOEFS$$#:
  2. Code organization Workspaces The go tool is designed to work

    with open source code maintained in public repositories. Although you don't need to publish your code, the model for how the environment is set up works the same whether you do or not. Go code must be kept inside a workspace. A workspace is a directory hierarchy with three directories at its root: src contains Go source files organized into packages (one package per directory), pkg contains package objects, and bin contains executable commands. The go tool builds source packages and installs the resulting binaries to the pkg and bin directories. The src subdirectory typically contains multiple version control repositories (such as for Git or Mercurial) that track the development of one or more source packages. To give you an idea of how a workspace looks in practice, here's an example: bin/ hello # command executable outyet # command executable pkg/ linux_amd64/ github.com/golang/example/ stringutil.a # package object src/ github.com/golang/example/ .git/ # Git repository metadata hello/ hello.go # command source outyet/ main.go # command source main_test.go # test source stringutil/ reverse.go # package source reverse_test.go # test source https://golang.org/doc/code.html
  3. github.com/golang/example/ stringutil.a # package object src/ github.com/golang/example/ .git/ # Git

    repository metadata hello/ hello.go # command source outyet/ main.go # command source main_test.go # test source stringutil/ reverse.go # package source reverse_test.go # test source This workspace contains one repository (example) comprising two commands (hello and outyet) and one library (stringutil). A typical workspace would contain many source repositories containing many packages and commands. Most Go programmers keep all their Go source code and dependencies in a single workspace. Commands and libraries are built from different kinds of source packages. We will discuss the distinction later. The GOPATH environment variable The GOPATH environment variable specifies the location of your workspace. It is likely the only environment variable you'll need to set when developing Go code. To get started, create a workspace directory and set GOPATH accordingly. Your workspace can be located wherever you like, but we'll use $HOME/go in this document. Note that this must not be the same path as your Go installation. $ mkdir $HOME/go $ export GOPATH=$HOME/go For convenience, add the workspace's bin subdirectory to your PATH: $ export PATH=$PATH:$GOPATH/bin Package paths https://golang.org/doc/code.html
  4. Code organization Workspaces The go tool is designed to work

    with open source code maintained in public repositories. Although you don't need to publish your code, the model for how the environment is set up works the same whether you do or not. Go code must be kept inside a workspace. A workspace is a directory hierarchy with three directories at its root: src contains Go source files organized into packages (one package per directory), pkg contains package objects, and bin contains executable commands. The go tool builds source packages and installs the resulting binaries to the pkg and bin directories. The src subdirectory typically contains multiple version control repositories (such as for Git or Mercurial) that track the development of one or more source packages. To give you an idea of how a workspace looks in practice, here's an example: bin/ hello # command executable outyet # command executable pkg/ linux_amd64/ github.com/golang/example/ stringutil.a # package object src/ github.com/golang/example/ .git/ # Git repository metadata hello/ hello.go # command source outyet/ main.go # command source main_test.go # test source stringutil/ reverse.go # package source reverse_test.go # test source ͕͜͜(01"5) https://golang.org/doc/code.html
  5. ݕࡧΩʔϫʔυ  ݕࡧ  2015-01  Go  τοϓ 

    mલͷ೔ه  ݄   ࠷৽  ࣍ͷ೔ه  ਫ  {  ฤू  )TCU%JBSZ  Ր  <௕೥೔ه> ˙XPSLJOHTQBDFΛHP४ڌʹͨ͠ ৄࡉ͸HIRΛ࢖ͬͨϩʔΧϧϦϙδτϦͷ౷Ұతɾޮ཰తͳ؅ཧʹ͍ͭͯEFMJSJPVTUIPVHIUTΛಡΜͰ͍ͩ͘͞ɻৄ͍͠಺༰ ͸શ෦ॻ͍ͯ·͢ɻ ΜͰ΋ͬͯɺݱঢ়͔ΒͲ͏Ҡߦ͢Ε͹͍͍ͷ͔ͱ͍͏࿩Ͱ͕͢ɺࠓ·ͰDQBO HFNT SBJMTΈ͍ͨʹԿͱͳ͘෼ྨ͍ͯͨ͠σΟϨ ΫτϦΛશ෦·ΔͬͱHP४ڌͷߏ଄ʹҠߦ͢ΔεΫϦϓτΛͰͬͪ͋͛·ͨ͠ IUUQTHJUIVCDPNITCUTDSJQUTCMPCNBTUFSHJUHPSC ࣗ෼͸d%PDVNFOUTΛdTSDͷΑ͏ʹ࢖͍ͬͯΔͷͰUBSHFUEJS͸d%PDVNFOUTʹͳͬͯ·͕͢ɺద౰ʹม͑ͯ࢖ͬͯͩ͘͞ ͍ɻ 2 1 ͍͍Ͷʂ ͍͍Ͷʂ <ποίϛΛೖΕΔ> ποίϛɾίϝϯτ͕͋Ε͹Ͳ͏ͧTQBNରࡦͰ&NBJMཝ͸Ӆͯ͋͠Γ·͢ɻ΋͠&NBJMཝ͕ݟ͍͑ͯͯ΋ɺԿ΋ೖྗ͠ͳ͍ͰԼ͍͞ɻ·ͨɺ63*͸ͭ· ͰೖྗՄೳͰ͢ɻ ໊͓લ ίϝϯτ ౤ߘ http://www.hsbt.org/diary/20140603.html
  6. HIR

  7. Explore Features Enterprise Blog HTTPS clone URL You can clone

    with HTTPS or Subversion. ghq / ! latest&commit&b6f7aadbeb Remote repository management made easy update doc motemen authored on Dec 9, 2014 " utils modify "svn" category log color as git, hg 3 months ago " zsh fixup docs and zsh completion 3 months ago # .gitignore initial version 9 months ago # .travis.yml make test 8 months ago # CHANGELOG.md Version 0.4: Introduced per-URL configuration 7 months ago # LICENSE MIT license 7 months ago # Makefile implemented ghq import < FILE 5 months ago $ README.asciidoc doc 9 months ago # commands.go modify clone error message 3 months ago # commands_test.go `ghq get -shallow` to perform `git clone --depth 1` 7 months ago # ghq.txt update doc a month ago # git.go Git version testing 7 months ago # git_test.go Git version testing 7 months ago % Sign up Sign up Sign in Sign in Search 361 33 ⋆ ⋆ Star Star ' ' Fork Fork motemen / ghq ( ) Code * Issues 3 + Pull Requests 5 , Pulse - Graphs https://github.com/motemen/ghq. ! ! ? . . Clone in Desktop Clone in Desktop / / Download ZIP Download ZIP 182 commits 7 branches 12 releases 21 contributors 6 2 7 5 0 0 1 1 2 2 master master branch: + This repository https://github.com/motemen/ghq
  8. Explore Features Enterprise Blog HTTPS clone URL You can clone

    with HTTPS or Subversion. peco / ! latest&commit&892f828463 Simplistic interactive filtering tool Merge pull request #219 from jedipunkz/master lestrrat authored 11 days ago " build Fix build script a month ago " cmd/peco version++; this is v0.2.11 a month ago " keyseq exec gofmt 5 months ago # .gitignore slight addition to .gitignore 2 months ago # .travis.yml remove 1.1 a month ago # Changes version++; this is v0.2.11 a month ago # LICENSE Initial commit 8 months ago # README.md fixed typos 2 months ago # action.go fixed a reverse order problem of SelectNext and SelectPrevious key. 11 days ago # action_test.go Fix a bunch of race conditions 3 months ago # config.go Start adding test for layout 5 months ago # config_darwin.go golint 6 months ago # config_posix.go golint 6 months ago $ Sign up Sign up Sign in Sign in Search 1,997 69 ⋆ ⋆ Star Star & & Fork Fork peco / peco ' ( Code ) Issues 3 * Pull Requests 0 + Wiki , Pulse - Graphs https://github.com/peco/peco.gi ! ! ? . . Clone in Desktop Clone in Desktop / / Download ZIP Download ZIP 694 commits 5 branches 25 releases 24 contributors 4 2 5 6 0 0 1 1 2 2 master master branch: + … This repository https://github.com/peco/peco
  9. function peco-src () { local selected_dir=$(ghq list --full-path | peco

    --query "$LBUFFER") if [ -n "$selected_dir" ]; then BUFFER="cd ${selected_dir}" zle accept-line fi zle clear-screen } zle -N peco-src [TISD
  10. )0.&ͱ(01"5)ͱࢲ
 —HOME, GOPATH and me ઃᒜ༸࣐
 !EBSBTIJ Sapporo #golang Meetup


    2015-01-21 5IFNBTDPUXBTEFTJHOFECZ3FOÉF'SFODI
 -JDFOTFEVOEFS$$#: