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
660
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
310
ISUCON出ようぜ!
taxio
0
66
Shutdown workers
taxio
0
220
catchup.pdf
taxio
0
55
Layered Architecture
taxio
0
93
SummerReport
taxio
0
68
ReactTutorial
taxio
0
71
ボスキタスイッチ.pdf
taxio
0
330
Other Decks in Programming
See All in Programming
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
RubyLSPのマルチバイト文字対応
notfounds
0
120
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
役立つログに取り組もう
irof
28
9.6k
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Jakarta EE meets AI
ivargrimstad
0
600
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
It's Worth the Effort
3n
183
27k
Speed Design
sergeychernyshev
24
610
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
The Cult of Friendly URLs
andyhume
78
6k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
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
Ҏ্ʂ ͓ർΕ༷Ͱͨ͠ʂ