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
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
Security_for_introducing_eBPF
kentatada
0
110
talk-with-local-llm-with-web-streams-api
kbaba1001
0
180
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
103 Early Hints
sugi_0000
1
230
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
Go の GC の不得意な部分を克服したい
taiyow
2
780
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Why Our Code Smells
bkeepers
PRO
335
57k
Designing for humans not robots
tammielis
250
25k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Automating Front-end Workflow
addyosmani
1366
200k
The Invisible Side of Design
smashingmag
298
50k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Music & Morning Musume
bryan
46
6.2k
How GitHub (no longer) Works
holman
311
140k
Thoughts on Productivity
jonyablonski
67
4.4k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
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
Ҏ্ʂ ͓ർΕ༷Ͱͨ͠ʂ