$30 off During Our Annual Pro Sale. View Details »

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$$#:

    View Slide

  2. l(PʹೖΓͯ͸(Pʹै͑z
    —Yoji Shidara, 7 Jul 2014.
    https://twitter.com/darashi/status/486031334591062018

    View Slide

  3. lࢲz

    View Slide

  4. CV[[UUFSDPN

    ˠݱߦͷόοΫΤϯυ͸΄΅(P
    (PSPPOHB
    ˠશจݕࡧΤϯδϯ(SPPOHBͷ(PόΠϯσΟϯά
    ࠷ۙͷ͓࢓ࣄ

    ˠؾ͕͍ͭͨΒେମ(P

    View Slide

  5. 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

    View Slide

  6. 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

    View Slide

  7. 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

    View Slide

  8. Έͳ͞Μ͸HJUDMPOFͨ͠

    σΟϨΫτϦΛ

    Ͳ͜ʹஔ͍͍ͯ·͔͢

    View Slide



  9. ͓࢓ࣄ͸dXPSL
    ͦΕҎ֎͸dHJU

    View Slide

  10. ͱ͸͍͑ʜ

    View Slide

  11. dHJUʹஔ͘Α͏ͳ

    ϓϩδΣΫτΛ

    ͓࢓ࣄͰ৮Δ͜ͱ΋͋Δ

    View Slide

  12. lXPSLͱ͸Կ͔z

    View Slide

  13. ৺ͷ໎͍͸

    σΟϨΫτϦͷ໎͍

    View Slide

  14. ͋ͷϚγϯͱ͜ͷϚγϯͰ

    ಉ͡ϓϩδΣΫτ͕

    ඍົʹҧ͏഑ஔʹ

    View Slide

  15. ΍΍͍͜͠

    View Slide

  16. ͦ͜Ͱʜ

    View Slide

  17. ࠷ۙ)0.&Λ

    (01"5)ʹͯ͠Έͨͱ͜Ζ

    ҙ֎ͱ͍͍ײ͡

    View Slide

  18. FYQPSU(01"5))0.&

    View Slide

  19. HJUIVCDPNEBSBTIJHPSPPOHB
    ˠdTSDHJUIVCDPNEBSBTIJHPSPPOHB

    View Slide

  20. HJUFYNQMFDPNIJNJUTVBXFTPNFXPSL
    ˠdTSDHJUFYBNQMFDPNIJNJUTVBXFTPNFXPSL

    View Slide

  21. (PҎ֎ͷϓϩδΣΫτ΋

    શͯ͜ͷϧʔϧͰ഑ஔ͢Δ

    View Slide

  22. ༧૝͞ΕΔ൓Ԡ

    View Slide

  23. lͳʹͦΕΩϞ͍z

    View Slide

  24. 5IFNBTDPUXBTEFTJHOFECZ3FOÉF'SFODI

    -JDFOTFEVOEFS$$#:

    View Slide

  25. l͙ͪΌ͙ͪΌʹͳΔͷͰ͸z

    View Slide

  26. 5IFNBTDPUXBTEFTJHOFECZ3FOÉF'SFODI

    -JDFOTFEVOEFS$$#:

    View Slide

  27. l(PʹೖΓͯ͸(Pʹै͑z
    —Yoji Shidara, 7 Jul 2014.
    https://twitter.com/darashi/status/486031334591062018

    View Slide

  28. ࣮͸(PΛॻ͔ͳ͍ਓʹ΋

    Φεεϝ

    View Slide

  29. ΂ΜΓ

    View Slide

  30. ͜Ε͸XPSL͔ MJGF͔ʁ
    XPSLͱ͸Կ͔
    ͱ͔ߟ͑ͳ͍͍ͯ͘

    View Slide

  31. ಉ͡ϓϩδΣΫτ͸

    ͲͷϚγϯͰ΋

    উखʹಉ͡৔ॴʹஔ͔ΕΔ

    View Slide

  32. ୳͢ͱ͖΋͙͢ʹݟ͔ͭΔ

    View Slide

  33. ࣮͸(JUαʔό໊΍

    (JU)VCͷ0SHBOJ[BUJPO

    ͕ҧ͏͜ͱʹΑͬͯ

    ͦͦ͜͜ϚτϞʹ෼ྨ͞ΕΔ

    View Slide

  34. ʮ΅͘ͷߟ͑ͨ࠷ڧͷ෼ྨʯ
    ΑΓ͸Πέͯͳ͍͔΋

    ʜͰ΋ߟ͑Δඞཁ͕ͳ͘ͳΔ
    ු͍ͨ෼Ͱ΋ͬͱผͷ͜ͱΛߟ͑Α͏

    View Slide

  35. (Pͱ஥ྑ͠

    View Slide

  36. ͍·͍ͪͳͱ͜Ζ

    View Slide

  37. ϓϩδΣΫτ։࢝͢Δͱ͖

    Ͳ͜ʹஔ͔͘໰୊
    ˠdTSDHJUIVCDPNEBSBTIJʹ

    ஔ͘Α͏ʹ͍ͯ͠Δ يಓʹ৐ͬͨΒ݁ہ(JU)VCʹஔ͘

    View Slide

  38. ϓϩδΣΫτ͕Ҡಈͨ͠Β

    ໘౗
    ˠେৎ෉ɺͦΜͳʹසൟʹ͸Ҡಈ͠ͳ͍

    View Slide

  39. ศར৘ใ

    View Slide

  40. Ҡߦ

    View Slide

  41. ݕࡧΩʔϫʔυ ݕࡧ 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

    View Slide

  42. HIR

    View Slide

  43. 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

    View Slide

  44. QFDP

    View Slide

  45. 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

    View Slide

  46. HIRQFDP

    View Slide

  47. 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

    View Slide

  48. (PΛ৮͍ͬͯΔͱײ͡Δ͜ͱ

    View Slide

  49. Ұݟ͢Δͱҧ࿨ײ͕͋Δ͚ΕͲ

    ࣮ࡍʹ΍ͬͯΈΔͱ

    ͳΔ΄Ͳײ͕ੜ͡Δ

    View Slide

  50. l(PʹೖΓͯ͸(Pʹै͑z
    —Yoji Shidara, 7 Jul 2014.
    https://twitter.com/darashi/status/486031334591062018

    View Slide

  51. )0.&ͱ(01"5)ͱࢲ

    —HOME, GOPATH and me
    ઃᒜ༸࣐

    !EBSBTIJ
    Sapporo #golang Meetup

    2015-01-21
    5IFNBTDPUXBTEFTJHOFECZ3FOÉF'SFODI

    -JDFOTFEVOEFS$$#:

    View Slide