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
670
Go CLI Hands-on
taxio
June 22, 2019
Tweet
Share
More Decks by taxio
See All by taxio
go gc algorithm 101
taxio
12
9k
go-gc-1
taxio
1
320
ISUCON出ようぜ!
taxio
0
69
Shutdown workers
taxio
0
220
catchup.pdf
taxio
0
57
Layered Architecture
taxio
0
96
SummerReport
taxio
0
69
ReactTutorial
taxio
0
72
ボスキタスイッチ.pdf
taxio
0
340
Other Decks in Programming
See All in Programming
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
290
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
400
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
500
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
780
Featured
See All Featured
Optimizing for Happiness
mojombo
376
70k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
A better future with KSS
kneath
238
17k
Mobile First: as difficult as doing things right
swwweet
222
9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
It's Worth the Effort
3n
183
28k
Become a Pro
speakerdeck
PRO
26
5k
Thoughts on Productivity
jonyablonski
67
4.4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
A Tale of Four Properties
chriscoyier
157
23k
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
Ҏ্ʂ ͓ർΕ༷Ͱͨ͠ʂ