Understand Go Modules / Go Modulesを理解する

5d769d109697012317c09c6a27a6a4bf?s=47 linyows
February 12, 2019

Understand Go Modules / Go Modulesを理解する

Fukuoka.go#13 + Okayama.go で話した資料です。Feb 12, 2019

5d769d109697012317c09c6a27a6a4bf?s=128

linyows

February 12, 2019
Tweet

Transcript

  1. 'VLVPLBHP 5PNPIJTB0EB (.01FQBCP *OD 'FCSVBSZ  (P.PEVMFTΛཧղ͢Δ

  2. 'VLVPLBHP (.0ϖύϘ ϓϦϯγύϧΤϯδχΞ !MJOZPXT CMPHUPNPIJTBPEBDPN

  3. 'VLVPLBHP 8&# %#13&44WPM )BTIJ$PSQ7BVMUͷهࣄدߘ ϦϙδτϦͷϦιʔεมߋΛݕ ஌ͯ͠ΞϓϦ͕ೳಈతʹσϓϩ ΠΛߦ͏ιϑτ΢ΣΞ MJOVYϢʔβͷ໊લղܾΛ (JU)VC͔ΒϚοϐϯά͢Δ ιϑτ΢ΣΞͷ։ൃ

  4. 'VLVPLBHP (P.PEVMFT࢖͍ͬͯ·͔͢

  5. 'VLVPLBHP ๏ ॳظɿ.BLFpMFͰґଘؔ܎Λղܾ͍ͯͯ͠Կ΋ͳ͍ࠒ ๏ HPHFUɿϦϙδτϦ͔Β௚઀औಘ໊͠લ໰୊΋ͳ͘γϯϓϧͰ࠷ߴͩͬͨ ๏ HPEFQɿόʔδϣϯࢦఆʹΑΓϏϧυ࠶ݱੑ໰୊Λղܾͯ͘͠Εͨ ๏ HPNPEVMFTɿόʔδϣχϯά͕ಁաతͰ(PΒ͠͞ΛऔΓ໭ͨ͠ (PύοέʔδػߏͷભҠ

  6. 'VLVPLBHP (P.PEVMFTͷجຊ

  7. 'VLVPLBHP ๏ ޙํޓ׵ੑΛڧ͘ҙࣝʢࢦఆʣͨ͠όʔδϣχϯά ๏ .BKPS.JOPS1BUDI͜ͷϑΥʔϚοτ͸େମ޿·͍ͬͯΔ͸ͣ ๏ όʔδϣχϯάʹϧʔϧ͕͋Ε͹ར༻ଆ͸Θ͔Γ΍͍͢ʢύοέʔδϚωʔ δϟͷ࣮૷͕γϯϓϧʹͳΔʣ ๏ ݴޠϨϕϧͰͷޙํޓ׵ͷடং͸Ϗϧυͷ࠶ݱՄೳੑ޲্ʹͳΔ

    େࣄͳϧʔϧɿ4FNBOUJD7FSTJPOJOH
  8. 'VLVPLBHP ๏ ࠷৽ͷόʔδϣϯ͸ৗʹߋ৽͞ΕΔ͕࠷ݹͷόʔδϣϯ͸ϢχʔΫͰ͋Δ ๏ ଞऀͱϏϧυͨ͠όΠφϦ͕ಉ͡Ͱ͋Δ͜ͱΛอূ͢Δ࢓૊Έ ๏ ύοέʔδϚωʔδϟʹͱͬͯ͸࠷৽͕࠷ߴͰ͸ͳ͍ ๏ ࠶ݱՄೳੑΛ௥ٻͨ݁͠Ռ ͓΋͠Ζґଘੑղܾɿ.JOJNBM7FSTJPO4FMFDUJPO

  9. 'VLVPLBHP ๏ ϕϯμϦϯά͸΋͏͠ͳ͍ͷͰϧʔτσΟϨΫτϦʹϑΝΠϧ͸࡞Βͳ͍ ʢϕϯμϦϯά͸͕࢖͑ͳ͍ͷͰ.BLFpMFͰؤுͬͯͯඍົͩͬͨʣ ๏ (01"5)TSD͔Β(01"5)QLHNPE഑Լ΁ ๏ ΩϟογϡͳͷͰؾܰʹHPDMFBONPEDBDIF͢Δ ๏ ա౉ظͰTSD഑ԼͱQLH഑Լͷ྆ํʹࢿ࢈͕͋Γόʔδϣχϯά͕͓͔͘͠ͳΔ

    ͕࣌͋Δʢ☝ͷΩϟογϡ࡟আͰ௚ͬͨΓ͢Δʣ ͞ΑͳΒϕϯμϦϯάʢόʔδϣχϯάΩϟογϡ΁ʣ
  10. 'VLVPLBHP ๏ ݴޠϨϕϧͰͷύοέʔδϚωʔδϟ࣮૷ʹΑΓ(PίϚϯυͷ࣮ߦ͸ґ ଘղܾͱϦϞʔτ͔Βμ΢ϯϩʔυΛࣗಈతʹߦͬͯ͘ΕΔ ๏ ΋ͪΖΜHPNPEʹόʔδϣϯࢦఆ΍ېࢭόʔδϣϯࢦఆ͕Ͱ͖Δ͠ɺ SFQMBDFͰҰ෦ϩʔΧϧύοέʔδΛࢦఆ͢Δ͜ͱ΋Ͱ͖Δ ๏ ͭ·ΓɺԿ΋͠ͳ͍Ͱ͍͍͠ม͚͑ͨΕ͹৭ʑͰ͖Δ࠷ߴ Ϣʔβ͕ҙࣝ͠ͳ͍όʔδϣχϯά

  11. 'VLVPLBHP (P.PEVMFTͷ࢖༻ྫ

  12. 'VLVPLBHP FYQPSU(0.0%6-&4PO͔Β࢝ΊΑ͏

  13. 'VLVPLBHP $ go test -v ./… -timeout 30s -parallel 8

    $ go build . $ go run main.go go: finding github.com/pierrec/lz4 v2.0.2+incompatible go: finding github.com/lestrrat-go/pdebug v0.0.0-20180220043849-39f9a71bcabe go: finding github.com/jessevdk/go-flags v1.4.0 go: finding github.com/dsnet/compress v0.0.0-20171208185109-cc9eb1d7ad76 go: finding github.com/mholt/archiver v0.0.0-20180417220235-e4ef56d48eb0 go: finding github.com/lestrrat-go/server-starter v0.0.0-20150105222616-88699d57aeee go: finding github.com/google/go-github v17.0.0+incompatible go: finding github.com/hashicorp/logutils v0.0.0-20150609070431-0dc08b1671f3 go: finding github.com/nwaples/rardecode v0.0.0-20171029023500-e06696f847ae go: finding github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82 go: finding github.com/pierrec/xxHash v0.1.1 … RUN ී௨ʹ࢖͏͚ͩͰཪͰ͍͍ײ͡ʹ΍ͬͯ͘ΕΔʢऴྃʣ
  14. 'VLVPLBHP Α͋͘Δґଘύοέʔδͷϝϯςφϯε

  15. 'VLVPLBHP # ґଘύοέʔδͷҰཡ $ go mod graph //or $ go

    list -m -f '{{.Version}}' all github.com/linyows/dewy github.com/pkg/errors@v0.8.0 github.com/linyows/dewy github.com/pmezard/go-difflib@v1.0.0 github.com/linyows/dewy github.com/stretchr/testify@v1.2.2 # ߋ৽͕Մೳͳύοέʔδόʔδϣϯͷදࣔ $ go list -u -m all | grep '\[.*\]' github.com/pkg/errors v0.8.0 [v0.8.1] github.com/pmezard/go-difflib v1.0.0 github.com/stretchr/testify v1.2.2 [v1.3.0] # Ұׅߋ৽ $ go get -u ґଘύοέʔδͷόʔδϣϯΛ্͛Δ
  16. 'VLVPLBHP # ґଘύοέʔδͷόʔδϣϯͷҰཡ $ go list -versions -m all github.com/pkg/errors

    v0.1.0 v0.2.0 v0.3.0 v0.4.0 v0.5.0 v0.5.1 v0.6.0 v0.7.0 v0.7.1 v0.8.0 v0.8.1 github.com/pmezard/go-difflib v1.0.0 github.com/dummy/log v1.1.1 v1.1.2 v1.1.3 v1.1.4 v1.2.0 v1.2.1 v1.2.2 v1.3.0 # ύοέʔδͷμ΢ϯάϨʔυ $ go get github.com/dummy/log@v1.2.2 # editίϚϯυ͔Β௥Ճ΍আ֎͕Ͱ͖Δʢgo.modͷߋ৽ʣ $ go mod edit -exclude github.com/dummy/log@v1.3.0 ໰୊ͷ͋ΔύοέʔδͷόʔδϣϯΛԼ͛Δ
  17. 'VLVPLBHP (P.PEVMFTͰࠔͬͨ͜ͱ

  18. 'VLVPLBHP w (Pͷ$-*πʔϧ͕HPNPEVMFTରԠͯ͠ͳ͍(0.0%6-&4PGGʹ͢Δ͔13Λ ૹΓ·͠ΐ͏ʢେࣄͳ׆ಈͰ͢ʣ w 1SPKFDUͰ௚઀࢖Θͳ͍ύοέʔδΛHPHFU͢ΔͱHPNPE͕ߋ৽͞ΕΔ͚͍ܽͯΔ ύοέʔδͷ௥Ճ΍ඇґଘύοέʔδΛഉআΛߦ͏HPNPEUJEZΛ࢖͍·͠ΐ͏ʢ࣮ ͸(PͰղܾ͍ͯ͠·͢ʣ w 1SPKFDUͰ௚઀࢖ͬͯͳ͍͚Ͳ$-*πʔϧΛνʔϜͰόʔδϣϯݻఆ͢ΔͨΊʹHPNPE

    ʹఆ͍ٛͨ͠EVNNZͷύοέʔδΛ࡞ͬͯ1"5)ࢦఆͯ͠HPJOTUBMM͢Δ w ґଘύοέʔδͷҰ෦ΛϩʔΧϧͷ΋ͷΛ࢖͍͍ͨSFQMBDFͰϩʔΧϧͯ͢͠Ε͹ ͍͚·͢ʢW͡Όͳ͍ͱμ ϝ͔΋ʣ
  19. 'VLVPLBHP IUUQTHJUIVCDPNHPMBOHHPJTTVFTJTTVFDPNNFOU $ export GOBIN=$PWD/bin $ export PATH=$GOBIN:$PATH $ cat

    tools.go 1 // +build tools 2 package tools 3 4 import ( 5 _ "github.com/linyows/git-semv/cmd/git-semv" 6 ) $ go install github.com/linyows/git-semv/cmd/git-semv $ type git-semv /Users/linyows/projectx/bin/git-semv
  20. 'VLVPLBHP .PEVMFTPG(P

  21. 'VLVPLBHP ๏ NPEVMF֎ͰNPEVMFૢ࡞͕Ͱ͖ΔΑ͏ʹͳͬͨʢHPHFU HPMJTU HPNPEEPXOMPBE͠ ͯ΋ॳظঢ়ଶΛҡ࣋͢Δʣ ๏ HPίϚϯυΛฒߦ࣮ߦ͕҆શʹͳͬͨʢpMFTZTUFN͕pMFMPDLJOHΛαϙʔτ͍ͯ͠Δ ඞཁ͕͋Δʣ ๏

    HPNPEʹHPόʔδϣϯσ ΟϨΫςΟϒͷαϙʔτʢͳ͚Ε͹DVSSFOUSFMFBTFΛ௥Ճ͢ Δ ๏ NPEVMFΛJNQPSUͰ͖ͳ͍৔߹ʹΩϟογϡ΍ωοτϫʔΫιʔεΑΓઌʹSFQMBDFͰ ࢦఆͨ͠ϩʔΧϧΛݟΔΑ͏ʹͳͬͨ .PEVMFTPG(P
  22. 'VLVPLBHP $PODMVTJPO

  23. 'VLVPLBHP ๏ (P.PEVMFT͸(Pͷγϯϓϧ͞Λҡ࣋ͭͭ͠Ϗϧυ࠶ݱੑΛॏࢹͨ͠ઃܭ ʹͳ͍ͬͯͯɺࢲͨͪ͸ޙํޓ׵ੑΛڧ͘ҙࣝ͠ͳ͚Ε͹ͳΒͳ͍ ๏ (P.PEVMFTͷઃܭࢥ૝Λ஌Δ͜ͱͰ໰୊͕ى͖ͯ΋ରॲ͢Δ͜ͱ͕Ͱ͖ Δ͠ɺ໰୊Λཧղ͢Δ͜ͱ͕Ͱ͖Δ ๏ (P.PEVMFT͸όϯόϯ࢖͍͖ͬͯ·͠ΐ͏ $PODMVTJPO

  24. 'VLVPLBHP 5IBOLZPV 8FSFIJSJOH