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

実践Go - ツールの作成から配布まで

実践Go - ツールの作成から配布まで

Fukuoka.go#2の資料です
http://connpass.com/event/7559/

monochromegane

August 22, 2014
Tweet

More Decks by monochromegane

Other Decks in Technology

Transcript

  1. ʕ◔ϖ◔ʔ < Go! $ go run xxx.go # ίϯύΠϧ&࣮ߦ(mainؔ਺ΛؚΉgoϑΝΠϧΛࢦఆ) $

    go test ./... # ͢΂ͯͷύοέʔδͷςετΛ࣮ߦ $ go build # ίϯύΠϧ
  2. github.com/user/ src/ cmd/go-ls/ main.go # mainύοέʔδ go-ls.go # ࣗ࡞ύοέʔδ •

    go get ͞Εͨ৔߹ͷߏ੒ͱͳΔ$GOPATH/ϦϙδτϦ/Ϣʔ β/srcͷߏ੒ʹ͋Θ͓ͤͯ͘ͱimportͰͭ·͔ͮͳ͍ • mainύοέʔδ͸CLIͷΤϯτϦϙΠϯτͱͯ͠ίϚϯυϥ ΠϯҾ਺ͷղੳͱࣗ࡞ύοέʔδͷݺͼग़͠Λߦ͏ • ͜ΕʹΑΓɺࣗ࡞ύοέʔδͷػೳ͕֎෦ύοέʔδ͔Βར ༻͠΍͘͢ͳΔ ʕ◔ϖ◔ʔ < Go!
  3. bin/ go-ls # ࣮ߦίϚϯυ (mainύοέʔδ) pkg/ darwin_amd64/ # ΞʔΩςΫνϟ github.com/user/

    go-ls.a # ύοέʔδΦϒδΣΫτ (ࣗ࡞ύοέʔδ) • go install͸src഑Լ͔ΒύοέʔδΛ୳ͯ͠ίϯύΠϧ͢Δ ʕ◔ϖ◔ʔ < Go!
  4. $ brew tap user/formula $ brew install formula • ಠࣗformulaΛͭͬͯ͘ɺtapͰ௥Ճ͢Δ

    • ґଘؔ܎ʹ`go`ΛೖΕ͓͚ͯ͹ɺGoͷ։ൃ؀ڥ΋Ұॹʹߏங ͯ͘͠ΕΔ
  5. require 'formula' ! HOMEBREW_PT_VERSION='1.7.1' class Pt < Formula # FormulaΫϥεΛܧঝ

    homepage 'https://github.com/monochromegane/the_platinum_searcher' url ‘https://github.com/monochromegane/the_platinum_searcher.git',\ :tag => "v#{HOMEBREW_PT_VERSION}" version HOMEBREW_PT_VERSION ! depends_on 'go' => :build # Ϗϧυ࣌ͷΈGoΛΠϯετʔϧ depends_on 'hg' => :build # ֎෦ύοέʔδ͕code.google.comͷ৔߹Mercurial͕ඞཁ ! def install ENV['GOPATH'] = buildpath system 'go', 'get', ‘github.com/jessevdk/go-flags' mkdir_p buildpath/'src/github.com/monochromegane' ln_s buildpath, buildpath/'src/github.com/monochromegane/the_platinum_searcher' system 'go', 'build', '-o', 'pt', 'cmd/pt/main.go' bin.install 'pt' end end formula
  6. $ cd go/src $ GOOS=linux GOARCH=amd64 \ ./make.bash $ GOOS=linux

    GOARCH=amd64 \ go build • Homebrewͷ৔߹ɺ/usr/local/Cellar/go/1.3/libexec Basic
  7. $ gox $ gox Number of parallel builds: 4 !

    --> darwin/386: go-ls --> darwin/amd64: go-ls --> linux/386: go-ls • ฒߦίϯύΠϧ • ΦϓγϣϯͰର৅OS/ARCHࢦఆՄೳ -osarch=“linux/amd64" mitchellh/gox
  8. $ goxc $ goxc ... ! [goxc:archive-tar-gz] 2014/08/10 21:35:38 Artifact(s)

    archived to /Users/miyakey/bin/go-ls- xc/snapshot/go-ls_linux_amd64.tar.gz • ίϯύΠϧ݁ՌΛѹॖͰ͖ΔͷͰɺಉ࣮͡ߦϑΝΠϧ໊ʹͰ͖Δ • ΦϓγϣϯͰର৅OS/ARCHࢦఆՄೳ -bc="linux,!arm darwin" laher/goxc
  9. http://icons8.com/ push configure hook Docker Images build & test Docker

    Container deploy download heroku, Dotcloud, GAE, S3, SSH C, C++, Dart, Go, Haskell, Groovy, Java, Node.js, PHP, Python, Ruby, Scala
  10. http://icons8.com/ push configure hook Boxes build & test Box deploy

    download heroku, OpenShift, Amazon, RackSpace, DigitalOcean Node.js, Ruby, Python, PHP, Go, Java/Android GitHub releases
  11. require 'formula' ! HOMEBREW_PT_VERSION='1.7.1' class Pt < Formula homepage 'https://github.com/monochromegane/the_platinum_searcher'

    url "https://github.com/monochromegane/the_platinum_searcher/ releases/download/v#{HOMEBREW_PT_VERSION}/pt_darwin_amd64.zip" sha1 '00844c339ca864bdae77fe4481a103456760181e' ! version HOMEBREW_PT_VERSION def install bin.install 'pt' end end formula • URLࢦఆͰzipϑΝΠϧΛࢦఆ͢ΔͱίϯύΠϧࡁΈͷϑΝΠ ϧ͔ΒΠϯετʔϧͰ͖ͯΠϯετʔϧ࣌ؒΛ୹ॖͰ͖Δ