Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go CLI Hands-on
Search
taxio
June 22, 2019
Programming
0
650
Go CLI Hands-on
taxio
June 22, 2019
Tweet
Share
More Decks by taxio
See All by taxio
go gc algorithm 101
taxio
12
8.9k
go-gc-1
taxio
1
310
ISUCON出ようぜ!
taxio
0
65
Shutdown workers
taxio
0
210
catchup.pdf
taxio
0
55
Layered Architecture
taxio
0
91
SummerReport
taxio
0
68
ReactTutorial
taxio
0
70
ボスキタスイッチ.pdf
taxio
0
330
Other Decks in Programming
See All in Programming
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
140
いかにして不足・不整合なくデータ移行したか
tjmtmmnk
1
1k
役立つログに取り組もう
irof
24
7.7k
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
14
3.8k
CSC305 Lecture 13
javiergs
PRO
0
120
現場で役立つモデリング 超入門
masuda220
PRO
12
2.6k
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
100
offers_20241022_imakiire.pdf
imakurusu
2
310
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
580
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
320
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
3
1.1k
ActiveRecordの力でDBのメタデータを迅速に解析する
lnit
5
2.2k
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
41
9.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Typedesign – Prime Four
hannesfritz
39
2.4k
RailsConf 2023
tenderlove
29
870
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
5
140
Bash Introduction
62gerente
608
210k
The Art of Programming - Codeland 2020
erikaheidi
51
13k
Gamification - CAS2011
davidbonilla
80
5k
The Language of Interfaces
destraynor
154
24k
Optimizing for Happiness
mojombo
376
69k
Rails Girls Zürich Keynote
gr2m
93
13k
Building Applications with DynamoDB
mza
90
6k
Transcript
(PͰ$-*πʔϧΛ࡞Δʂ
ஸʹͳΓ·͕͢ Θ͍Θ͍͍͖ͬͯ·͠ΐ͏ʂ
w ࠓ$-*πʔϧΛ࡞ΔΛ͢ΔͷͰɼͦΕҎ֎ͷ(PͷͳΔ͘ආ͚ ·͢ɽ ຊ࣭ͱΕͨίʔυ͕૿͑ΔͷͰ w దٓɼ༨ஊͱ֤ͯ͠ϓϥΫςΟεͷิΛ͠·͢ɽ ͓͜ͱΘΓ 3
w ͳͥ(PͰ$-*πʔϧΛ࡞Δͷ͔ w ࠓ࡞Δπʔϧͷ༷Ѳ w ඪ४ϥΠϒϥϦͰ࡞ͬͯΈΔ w Πϯετʔϧͯ͠ΈΔ w ੩తϑΝΠϧΛόΠφϦʹຒΊࠐΉ
w 4DBMBCMFͳ࣮ʹ͢Δ 4DIFEVMF 4
ͳͥ(PͰ$-*πʔϧΛ࡞Δͷ͔
w HIR QFDP (PͰ࡞ΒΕ͍ͯΔπʔϧͨͪ 6
w จ๏͕γϯϓϧ w ίϯύΠϧݴޠ w γϯάϧόΠφϦ w ΫϩείϯύΠϧՄೳ w ίϛϡχςΟ͕׆ൃ
(PͷϝϦοτ 7
w γεςϚνοΫʹݎ࿚ͳαʔϏεΛΉͷۤख ‣ ͦ͏͍͏ͷ3VTUͱ͔ؔܕݴޠͷࣄ ‣ υϝΠϯϩδοΫʹूதͰ͖ͯߴʹαʔϏεΛͤ͞ΒΕΔͷ͕ڧΈ͔ͩΒ (Pͷۤखͳ͜ͱ 8
w IUUQTCFODINBSLTHBNFUFBNQBHFTEFCJBOOFUCFODINBSLTHBNF GBTUFTUHPHQQIUNM w (PίϯύΠϧݴޠ͚ͩͲ($͕Φʔόʔϔουʹͳͬͯগ͍͠ ‣ ͦͷΘΓϝϞϦ҆શ w ͔͠͠։ൃͱ࣮ߦ͕ͪΐ͏Ͳ͍͍
9
ααοͱ࡞Γ͍ͨ࣌ʹ બ͞ΕΔͷ͕(PMBOH
ࠓ࡞Δπʔϧͷհ
w EBJMZSFQP ‣ ใͷܗ࡞πʔϧ ‣ BEEαϒίϚϯυͰςϯϓϨʔτʹैͬͨϨϙʔτ࡞ - dailyrepo add --name
[name] w ࠓճงғؾΛ௫ΉͨΊʹػೳ࠷ݶ ใܗ࡞πʔϧ 12
࣮͍ͯ͘͠લʹ ͱ͜ΖͰօ͞Μ
งғؾͰ$-*πʔϧ ࡞͍ͬͯ·ͤΜ͔ʁ
࣮ͦΕɼϚφʔҧ͔
w ҾͲͷΑ͏ʹઃܭ͢Δ͖ʁ w ϑΝΠϧͷѻ͍Ͳ͏͢Δ͖ʁ w &YJU4UBUVTԿΛฦ͖͢ʁ w ࠔͬͨͱ͖ʹಡΉEFFFFU͞ΜͷૉΒ͍͠ࢿྉ ‣ IUUQTTQFBLFSEFDLDPNUDOLTNLPNBOEPSBJOUVSVOJUVJUFZVSVUPLJOJQV
GBMTFZVSVLPUPOVNCFSZBQDBTJB ‣ PQUJPOTͱBSHVNFOUTͷҐஔ͕ؔೖΕସΘͬͯΔͷΑ͘ݟΔ ࣮͢Δͱ͖ʹߟ͑Δ͜ͱ 16
104*9(/6TUZMF
w IUUQTQVCTPQFOHSPVQPSHPOMJOFQVCT w IUUQTXXXHOVPSHTPGUXBSFMJCDNBOVBMIUNM@NPOPMJCDIUNM w 6OJYΛ࢝Ίͱ֤ͨ͠छ04ؒͰҠ২͍͢͠ΞϓϦέʔγϣϯΛ ࡞ΔͨΊͷࠃࡍن֨ w ͍ͭ͜ΒͷৼΔ͍Λਅࣅ͓͚ͯ͠จ۟ݴΘΕͳͦ͞͏ 104*9(/6TUZMF
18
w "MMQSPHSBNTTIPVMETVQQPSU ‣ --version ‣ --help w MPOHPQUJPOΛ͏ w TIPSUPQUJPOΛ͏
‣ ϑϥάͷ߹·ͱΊΔ͜ͱ͕Ͱ͖ΔΑ͏ʹ FHls -al ‣ ҾΛऔΔ߹ɼؒʹεϖʔεΛͬͯΘͳͯ͘ྑ͍ FHmysql -uroot w IUUQTXXXHOVPSHTPGUXBSFMJCDNBOVBMIUNM@OPEF"SHVNFOU4ZOUBYIUNM 'MBH0QUJPOT 19
w جຊతʹ͕ޭͰ͕ࣦഊ w "EWBODFE#BTI4DSJQUJOH(VJEFʹࡌ͍ͬͯΔن֨ ‣ IUUQUMEQPSH-%1BCTIUNMFYJUDPEFTIUNM ‣ Ͳ͏ͤTIͰ࣮ߦ͢Δͱ͖CJOCBTIΛࢦఆ͢Δ͜ͱ͕ଟ͍͠ w 'SFF#4%ϥΠϒϥϦؔϚχϡΞϧ
‣ IUUQTLBXPSVKQOPSHEPD'SFF#4%KNBONBOTZTFYJUTQIQ w ͋Μ·ΓϋϯυϦϯάͯ͠ΔΞϓϦέʔγϣϯݟͨ͜ͱແ͍͚Ͳ &YJU4UBUVT 20
w 9%(#BTF%JSFDUPSZ ‣ IUUQTTUBOEBSETGSFFEFTLUPQPSHCBTFEJSTQFDMBUFTUJOEFYIUNM ‣ πʔϧͷઃఆϑΝΠϧΩϟογϡΛͲ͜ʹஔ͔͘Λఆ༷ٛͨ͠ॻ )0.&DPOpHͱ͔ w Ұ࣌తͳϑΝΠϧUNQʹஔ͘͜ͱଟ͍
6OJYɾ-JOVYܥ ϑΝΠϧͷѻ͍ 21
– @mygwdesign lσβΠϯར༻͢ΔͷɻΞʔτؑ͢Δͷɻz
$-*ΛσβΠϯ͠·͠ΐ͏
Ͱ͍࣮͟ʂ
w (JU)VCʹࠓͷϦϙδτϦΛ࡞͍ͬͯͩ͘͞ ‣ ࡞ͨ͠πʔϧΛ(JU)VC͔ΒΠϯετʔϧ͢Δͱ͖ʹ͍·͢ w ࠓͷܗ ‣ IUUQTHJUIVCDPNUBYJPHPDMJUVUPSJBM ‣ ໎ͬͨΒ͜͜Λࢀߟʹίϐϖ͍ͯͩ͘͠͞
w ϋϯζΦϯͳͷͰ͔Βͳ͍߹ͲΜͲΜखΛ্͍͛ͯͩ͘͞ ‣ ͚ͩͰख͕·ΘΒͳ͍͜ͱ͋ΔͷͰɼ ྡͷਓ͕ࠔ͍ͬͯΔ߹ڭ͍͑ͯ͋͛ͯͩ͘͞ ࡞͍ͬͯ͘ʹ͋ͨͬͯ 25
ඪ४ϥΠϒϥϦͰ࣮ͯ͠ΈΔ
w qBH ‣ IUUQTHPMBOHPSHQLHqBH ‣ ίϚϯυϥΠϯҾͰ͞ΕΔϑϥάͷύʔεपΓΛཧͯ͘͠ΕΔ ‣ ͱͯബ͍ϥΠϒϥϦͳͷͰͥͻιʔεΛݺΜͰงғؾΛ௫ΜͰΈ·͠ΐ͏ ϥΠϒϥϦհ 27
w ܗIUUQTHJUIVCDPNUBYJPHPDMJUVUPSJBMCMPCNBTUFSDNE EBJMZSFQPNBJOHP ‣ TUBUJLύοέʔδΛͬͯΔͷҰ୴ແࢹͯ͠ɼJPVUJM3FBE'JMF Λ͍ͬͯͩ͘͞ w σϑΥϧτͷqBHΦϒδΣΫτΛ͏ͱFSSPS)BOEMJOHʹ&YJU0O&SSPS͕ ઃఆ͞Ε͍ͯΔͷͰɼIFMQग़ྗ࣌ʹFYJUTUBUVTͰऴྃͯ͠͠·͏ ‣
AIA AIFMQAΛࣗͰఆٛ͢Εͳ͍ ࣮͢Δ 28
-JWF$PEJOH
w MPOHPQUJPOͰ͖·͢ ‣ IUUQNBUPQFIBUFOBCMPHDPNFOUSZ ‣ εϚʔτͰͳ͍ w TIPSUPQUJPO·ͱΊΕͳͦ͞͏ ‣ Βͳ͍͚ͩͰɼ͔ͨ͠͠ΒͰ͖Δ͔
w ͦͦ(Pࣗମ͕ͦ͏͍͏$-*Λఏڙ͍ͯ͠ͳ͍ qBHͰ104*9(/6TUZMFͳ$-*࡞Εͳ͍ʁ 30
Πϯετʔϧͯ͠ΈΔ
w go install͢Δͱ(01"5)CJOҎԼʹόΠφϦ͕ஔ͔ΕΔ w NBJOύοέʔδͷ͋ΔϦϞʔτϦϙδτϦΛgo getͯ͠0, ‣ HPHFUHJUIVCDPNUBYJPHPDMJIBOETPODNEEBJMZSFQP ‣ IUUQTHPMBOHPSHDNEHPIES
%PXOMPBE@BOE@JOTUBMM@QBDLBHFT@BOE@EFQFOEFODJFT w όΠφϦ໊ʁ ‣ NBJOύοέʔδͷ͋ΔσΟϨΫτϦ໊ )PXUPJOTUBMM 32
w (PͰखܰʹΫϩείϯύΠϧͰ͖Δͷ͕ڧΈͰͨ͠Ͷ ‣ GOOS={{OS໊}} GOARCH={{ΞʔΩςΫνϟ໊}} go build ‣ (PΠϯετʔϧ࣌ʹଞڥͷґଘೖΕ͓͚ͯ͜Ε͚ͩͰΫϩείϯύΠϧՄೳ ͷ
ͣ ‣ $(0ΛແޮԽ͓͚ͯ͠ɼTUBUJDMJOLͰ͖Δ CGO_ENABLED=0 ‣ ରԠڥIUUQTHPMBOHPSHEPDJOTUBMMTPVSDFFOWJSPONFOU w $*ͰόΠφϦੜͯ͠ɼ(JU)VCͷ3FMFBTFʹࡌͤΔͷ͕Α͋͘Δӡ༻ํ๏ ‣ (P3FMFBTFSΛ͏ͱָ ‣ IUUQTHJUIVCDPNHPSFMFBTFSHPSFMFBTFS ‣ IUUQTHPSFMFBTFSDPNDJ )PXUPDSPTTDPNQJMF 33
σΟϨΫτϦߏʹ͍ͭͯ 34 /Project main.go # package main lib/ dailyrepo.go #
package dailyrepo w ެ։͍ͨ͠ϓϩδΣΫτ͕πʔϧͳͷ͔ϥΠϒϥϦͳͷ͔ʹΑͬͯɼ σΟϨΫτϦߏେ͖͘มΘΔɽ ‣ ࢀߟΈΜͳͷ(Pݴޠ ࠓվగ൛͕ग़ΔΒ͍͠Ͱ͢ w Ϣʔβ͕go getͨ࣌͠ͷҙਤ͠ͳ͍JOTUBMMΛճආͤ͞Δ /Project dailyrepo.go # package dailyrepo cmd/ dailyrepo/ main.go # package main πʔϧ όΠφϦ ͕ϝΠϯͷՌͷ߹ ϥΠϒϥϦ͕ϝΠϯͷՌͷ߹
੩తϑΝΠϧΛຒΊࠐΉ
w (PͷڧΈͷ̍ͭʹγϯάϧόΠφϦͱ͍͏ͷ͕͋ͬͨ ‣ ੩తϑΝΠϧʹґଘ͢Δπʔϧͩͬͨ߹ɼͦͷϑΝΠϧΠϯετʔϧ࣌ʹ μϯϩʔυͤ͞Δͷʁ ‣ όΠφϦʹຒΊࠐΜ͡Ό͑ w SE1BSUZͷϥΠϒϥϦΛ࣮ͬͯ͢Δ ‣
KUFFVXFOHPCJOEBUBͱ͍͏ͷ͕͕͋ͬͨࠓ%FQSFDBUFE ͱ͍͏͔࡞ऀ͕(JU)VCΞΧϯτΛফͨ͠ ‣ "XFTPNF(PΛݟͯ୳ͦ͏ IUUQTBXFTPNFHPDPNSFTPVSDFFNCFEEJOH ຒΊࠐΉ 36
ҰԠެࣜͬΆ͍Γํʁ 37 $ go build -ldflags "-X main.Version=v0.0.1" w SE1BSUZʹཔΒͳͯ͘όΠφϦʹ੩తϑΝΠϧຒΊࠐΊΔ
w #VJME࣌ʹมʹΛຒΊࠐΉ͜ͱ͕Ͱ͖Δ ‣ (JUͷใΛऔͬͯ7FSTJPOΛຒΊࠐΉͷΑ͘ݟΔ w ͍Ͱ͜ΕͰϑΝΠϧͷ༰ΛຒΊࠐΉͷਏ͍
w IUUQTHJUIVCDPNSBLZMMTUBUJL w ੩తϑΝΠϧͷ[JQσʔλ όΠτྻ Λ(PίʔυͷதʹϋʔυίʔσΟϯά ͍ͯ͠Δɽ ‣ *TUIJTBDSB[ZJEFB /P
OPUOFDFTTBSZ SBLZMMTUBUJL 38
TUBUJLͰຒΊࠐΜͰΈΔ 39 # install $ go get github.com/rakyll/statik # ϑΝΠϧ࡞
$ statik --src=templates/ w ͖ͬ͞ͷςϯϓϨʔτϑΝΠϧಡΈࠐΈΛࠩ͠ସ͑·͠ΐ͏ ‣ IUUQTHJUIVCDPNUBYJPHPDMJUVUPSJBMCMPCNBTUFSDNEEBJMZSFQPNBJOHP
TUBUJLͰຒΊࠐΜͰΈΔ 40 bptl, err := ioutil.ReadFile("../../templates/report.md.tmpl") statikFs, err := fs.New()
if err != nil { log.Fatal(err) } tplFile, err := statikFs.Open("/report.md.tmpl") if err != nil { log.Fatal(err) } defer tplFile.Close() btpl, err := ioutil.ReadAll(tplFile)
-JWF$PEJOH
͜͜ͰҰ୴ʂ
Ͱػೳ͕૿͖͑ͯͨΒʁ ͜ͷϑϥάཧͰεέʔϧͰ͖Δ
4DBMBCMFͳ࣮ʹม͑Δ
w ϑϥάͷύʔαʔΛͬͱݡ͍ͷʹ͢Δ ‣ ྲྀੴʹTIPSU MPOHPQUJPOཉ͍͠ ‣ TIPSUPQUJPOΛ·ͱΊ͍ͨ w ςετ͍͢͠Α͏ʹ͢Δ ‣
ϑΝΠϧγεςϜૢ࡞ͩͬͯςετ͍ͨ͠ ‣ ඪ४ग़ྗͩͬͯςετ͍ͨ͠ ํ 45
None
w ͜ͷਓͷੈք؍ʹै͑େମඞཁͳػೳἧ͏ w QqBH ‣ 104*9(/6TUZMF४ڌͳqBHΑΓͪΐͬͱݡ͍ϑϥάύʔαʔ w DPCSB ‣ QqBHΛϕʔεʹ࡞ΒΕͨ$-*ϑϨʔϜϫʔΫ
w BGFSP ‣ ϑΝΠϧγεςϜͷநԽϥΠϒϥϦ w WJQFS ‣ ઃఆϑΝΠϧཧϥΠϒϥϦ TQGͱ͍͏εΰ͍ਓ 47
·ͣDPCSBͰ࣮͍ͯ͘͠ 48 # install $ go get github.com/spf13/cobra # init
$ cobra init dailyrepo --pkg-name github.com/{Ϣʔβʔ໊}/{ϦϙδτϦ໊}/cmd/dailyrepo # create `add` sub command $ cobra add add w ؤு͖ͬͯͬ͞ͷ࣮Λ࠶ݱ ‣ IUUQTHJUIVCDPNUBYJPHPDMJUVUPSJBMUSFFNBTUFSDNEEBJMZSFQPFY
-JWF$PEJOH
w IUUQTHJUIVCDPNBWFMJOPBXFTPNFHPTUBOEBSEDMJ w Α͘ฉͭ͘ ‣ KFTTFWELHPqBHT ‣ BMFDUIPNBTLJOHQJO ‣ VSGBDFDMJ
‣ NJUDIFMMIDMJ QqBH DPCSBҎ֎ͷબࢶ 50
TQGBGFSP 51 # install $ go get github.com/spf13/afero w IUUQTHJUIVCDPNTQGBGFSP
w ϑΝΠϧγεςϜͷૢ࡞ΛநԽͯ͘͠ΕΔϥΠϒϥϦ ‣ BGFSP'T0T04ଆͷϑΝΠϧγεςϜ ‣ BGFSP.FN.BQ'TϝϞϦ্ʹߏங͞ΕͨϑΝΠϧγεςϜ ςετ࣌ʹ͏
-JWF$PEJOH
w GNU1SJOUMO PT4UEPVUʹରͯ͠GNU'QSJOUMO ͍ͯ͠Δɽ ‣ PT4UEPVUΛCZUFT#V⒎FSʹࠩ͠ସ͑ΕΔΑ͏ʹ͓ͯ͘͠ w ࠓճWFSTJPOͷQSJOUΛςετͯ͠Έ·͢ ඪ४ग़ྗΛςετ͢Δ 53
-JWF$PEJOH
ʂ
w HJUIVCDPNTQGWJQFS ‣ ίϚϯυϥΠϯϑϥάɼڥมɼઃఆϑΝΠϧ KTPO UPNM ZBNM FUD ɼ ϦϞʔτઃఆγεςϜ
FUDE FUD ɼσϑΥϧτ͔ΒઃఆΛऔಘ͢Δɽ w os.UserHomeDir, os.UserCacheDir, os.UserConfigDir ͜Ε·ͩϦϦʔε͞Εͯͳ͍ Λͬͯ ઃఆϑΝΠϧΛݟ͚ͭΑ͏ ༨ஊઃఆϑΝΠϧͷ 56
w ࠷ۙͷπʔϧ݁ߏ(PͰॻ͔Ε͍ͯΔ w (Pͩͱ࡞࣌࡞ޙ͍͍͢$-*πʔϧΛ࡞Δ͜ͱ͕Ͱ͖Δ w டংͷແ͍$-*Ξʔτ ·ͱΊ 57
w MPHHJOH ‣ cobra.OnInitialize()ͰWFSCPTFͷਅِΛݟͯMPHͷઃఆΛม͑ͨΓ͢Δ w ΞʔΩςΫνϟ ‣ جຊతʹࠓͷϑΝΠϧγεςϜඪ४ग़ྗͷநԽͷΑ͏ͳΠϝʔδͰ ͦΕͧΕͷΛશ͏͢ΔϞδϡʔϧΛநԽ͍ͯ͘͠ ‣
(PͰ"1*αʔόʔΛ࣮͢Δͱ͖ϨΠϠʔυΞʔΩςΫνϟ͕Α͘࠾༻͞Ε·͢ w ΤϥʔϋϯυϦϯά ‣ (PͰYFSSPST͕ඪ४ͷFSSPSTʹΈࠐ·ΕΔΒ͍͠Ͱ͢ IUUQTHPHPPHMFTPVSDFDPNQSPQPTBM NBTUFSEFTJHOFSSPSWBMVFTNE ‣ ϋϯυϦϯάʹ͍ͭͯIUUQTNFEJVNDPNZBLLBCFUUFSHPFSSPSIBOEMJOHXJUI YFSSPSTFD ࠓͯ͠ͳ͍༰ 58
w HP[(Pʹؔ͢Δχϡʔε·ͱΊ ‣ IUUQHP[IFYBDPTBOFU w HPXJLJ৭ʑͳϓϥΫςΟε͕·ͱ·͍ͬͯΔ ‣ IUUQTHJUIVCDPNHPMBOHHPXJLJ w 5IF(P#MPHެࣜΞφϯεͱ͔
‣ IUUQTCMPHHPMBOHPSH ༨ஊ(PΛֶͼ͍ͨͳΒ 59
Ҏ্ʂ ͓ർΕ༷Ͱͨ͠ʂ