Goè¨èªãTDDã§å¦ãã§ã¿ã話ï¼ç¶ãï¼
æ°ããããã°ã©ãã³ã°è¨èªãTDDã使ã£ã¦å¦ã¶è©¦ã¿ã¨ãã¦ãä»åã¯Goè¨èªãå¦ãã§ãã¾ããè¨èªã®ä½æ³ãéçºç°å¢ããã£ã¼ãããã¯ãµã¤ã¯ã«ãæå³çã«åããªããå¦ã³ã¾ãã
ååããã®ç¶ã
ååã«å¼ãç¶ããGoè¨èªããã¹ãé§åéçºï¼TDDï¼ã使ããªããå¦ã³ãé²ãã¦ã¿ã¾ããååã®è¨äºã¯ãã¡ãããèªã¿ãã ããã
ãã¦ãã¾ãã¯ããã¾ã§ã®TODOãªã¹ããè¦ã¦ã¿ã¾ãããã#TODOã®ä¸ã¯ããããããã¹ãã¿ã¹ã¯ã§ã#DONEã®ä¸ã¯ãã§ã«å®äºããã¿ã¹ã¯ã«ãªãã¾ãã
#TODO
0ã®å ´åã4000ã®å ´åã¯ã¨ã©ã¼
4ã®å ´åã¯IV
9ã®å ´åã¯IX
5ã®å ´åã¯V
40ã®å ´å
50ã®å ´å
11ã®å ´åã¯XI
(1-3999ã§æãæ¼ãããã¨ã§...èãã)
gorename ã試ã
VSCodeã§ä¿åãããå³ãã¹ãå®è¡ã®æ¹æ³ãæ¢ã# DONE
10,20ã®å ´å
1 => Iã®å¤æãã§ãããã¨ã
APIã®è¦ç´ãï¼ãªãã¸ã§ã¯ãæå風ã®ã¡ã½ããã«ç½®ãæãï¼
Goã§ããè¦ããããã¼ã¿é§ååã®ãã¹ãã«ç½®ãæã
2 => IIã®å¤æãã§ãããã¨ã
ä»åã¯ãæ°ã«ãªã£ã¦ããã¨ã©ã¼ã±ã¼ã¹(0ã®å ´åã4000ã®å ´å)ãé²ãã¦ããã¾ãã
ã¨ããã®åã«ãVSCodeä¸ã§ä¿åãããå³ãã¹ãã®ããæ¹ãã©ããã¦ãæ°ã«ãªã£ã¦èª¿ã¹ã¦ã¿ã¾ãããã³ã¼ãã¨ããã¥ã¡ã³ãã追ã£ã¦ã¿ãã¨ãååå ¥ããæ©è½æ¡å¼µã使ããworkspace settings ã§ãgo.testOnSave: true ã追å ããã°OKã§ãã
ããã§ä¿åããããã¹ãå®è¡ãã§ããããã«ãªãã¾ãããå®ã«æ°åãè¯ãï¼ï¼
ç´ æ©ããã£ã¼ãããã¯ãµã¤ã¯ã«ãä½ã
TDDã®ã³ãï¼ ãã£ã¼ãããã¯ãµã¤ã¯ã«ãä½ããã¨ãç´ æ©ãå°ãããã£ã¼ãããã¯æ©æ§ãã§ããããã«æ¹åãç¶ãããã¨
ãã£ã¼ãããã¯ãµã¤ã¯ã«ãçããããã¨ã§ãåä½æéå½ããã®å¦ã³ã®æ°ãå¢ãããã¨ãã§ãã¾ããä¿åãããå³å®è¡ã®éå ·ã®æ¹åã®ã»ããæåã¨ç®è¦ã«ããç¹°ãè¿ã確èªãæ©æ¢°ã«ä»»ããèªåãã¹ãã¸ç½®ãæãããã£ã¼ãããã¯ãµã¤ã¯ã«ãçãããå ¸åçãªä¾ã§ããã
æéã®ãããããããããã¤ï¼ã¨ã³ããã¼ã¨ã³ããã¹ãããç´ç²ãªãã¡ã¤ã³ãã¸ãã¯é¨åã®ã¦ããããã¹ãã«æ³¨åãããã¨ã«ç½®ãæããããæ¹ãããã£ã¼ãããã¯ãµã¤ã¯ã«ãçãããæ¹æ³ã®ä¸ã¤ã§ããç´ç²ãªãã¸ãã¹ãã¸ãã¯ã¨ç°å¢ã®å¢çãè¦æ¥µãã¦åé¢ãããã¨ãã³ãã§ãããã¤ãã¢ãã¯ã«ã¤ãã¦ã解説ãããã¨æãã¾ãã
https://speakerdeck.com/twada/testable-lambda-working-effectively-with-legacy-lambda
ä½è«ã§ãããTDDãå«ãå¤éã®ãã£ã¼ãããã¯ãµã¤ã¯ã«æ©æ§ã®ä»çµã¿ã¥ããã¯ã½ããã¦ã§ã¢éçºããã¾ãããã³ãã§ããã¢ã¸ã£ã¤ã«ãTDDãDevOps ããªã¼ã³ã¹ã¿ã¼ãã¢ããããªã¼ãã³ã½ã¼ã¹ã®ã¨ã³ã·ã¹ãã ãæ ¹ã£ãã«ããã®ã¯ãã©ã¼ãããã¯æ©æ§ã§ããã¤ã¾ãã¯ãæ§ãæã¦çãã§ãã
Goè¨èªã§ã®ããæ¹ãå¦ã¶
xxx, err := <é¢æ°ãã¡ã½ããå¼ã³åºã>
if err != nil {
<ä½ãä¾å¤å¦ç>
return xxx
}
<é常ã®å¦ç>
Goè¨èªã®å¦ã³ï¼ è¤æ°ã®å¤ãè¿ããã¨ã©ã¼ãè¿ãã
Goã§ã¯é¢æ°ãã¡ã½ããã§ã¯è¤æ°ã®å¤ãè¿ããã¨ãã§ãã¾ããè¤æ°ã®å¤ãè¿ãifæã§ã¨ã©ã¼ãã§ãã¯ãã¾ããGoã§ã¯ããåºã¦ããã¤ãã£ãªã ãªã®ã§è¦ãã¦ããã¾ããããä»ã®ããã°ã©ãã³ã°è¨èªã§ããããä¾å¤ãæãã¦try-catch-finallyã§å¦çããæ§æã¯Goè¨èªã®å ´åã¯æä¾ãã¦ãã¾ããã
Goè¨èªã®ã¨ã©ã¼ãã³ããªã³ã°ã«ã¤ãã¦ã¯ã次ã®è¨äºãåèã«ãã¾ããã
ã¨ã©ã¼ã®å ´åã«è¤æ°ã®å¤ã«ã¨ã©ã¼ãå«ãã¦è¿ã以å¤ã«ãpanicã使ãæ¹æ³ãããã¾ãããã ããå復ä¸è½ãªã¨ã©ã¼å ´åã®ã¿ã«panicã使ããåºæ¬ã¯è¤æ°ã®å¤ã§ã¨ã©ã¼ãä¼ããå©ç¨è ã«æä¾ããAPIã®å¢çã§panicã§ä¼æããããã¨ã¯åºæ¬è¡ãã¾ãããæ°ã«ãªã£ã¦ããã¨ãããå°ãã¹ãããªãã¾ããã
panicã®ä½¿ãæ¹ã«ã¤ãã¦ã¯ã次ã®è¨äºãåèã«ãã¾ããã
æ¬å®¶ã®ããã¥ã¡ã³ããèªã
ããã°ã©ãã³ã°è¨èªã®å¦ç¿ã®ã³ãï¼æ¬å®¶ã®ããã¥ã¡ã³ããèªãã
éçºè ã¨ãã¦ãå人ã®ããã°ã®2次çãªæ å ±ããæ¬å®¶ã®ããã¥ã¡ã³ããèªãçã¯ä»ãã¦ããã¾ããããããã¥ã¡ã³ããè±èªã®å ´åãããã©ã¦ã¶ã®æ©è½æ¡å¼µãOSã«ã¤ãã¦ããè±èªè¾æ¸ãããã°ç´ãã«èª¿ã¹ããã¨ãåºæ¥ã¾ããæå¿ã«ãã£ã¦æ¬å®¶ã®ããã¥ã¡ã³ãã®æ¥æ¬èªè¨³ãè¡ããã¦ããå ´åãããã¾ããè£å©ã®æ å ±ã¨ãã¦ãæ¬å®¶ãæä¾ãã¦ããã³ã¼ããGitHubçã«ããã°ç´ãã«è©¦ãã¦å¦ã¶ãã¨ãã§ããã§ããããStackoverflowãQiitaã®æ å ±ãæ´»ç¨ãã¦ããã¾ããããæ å ±ãå¤ããªã£ã¦ãã¾ã£ãããã°ã®æ å ±ã«ã¯æ³¨æãå¿ è¦ã§ãã
ã¾ãã¯ã0ã§å¤æã§ããªããã¨ã®å¤±æãããã¨ã確èªãã¦ã
ãã¹ãããã¹ãããã¨ç¢ºèªãã¾ãã
Roman(ââ)ã®ä»£ããã« nilãè¿ããã¼ã¸ã§ã³ãªãã©ããªããæ°ã«ãªã£ãã®ã§è©¦ãã¦ã¿ã¾ããã
ãã£ã¨ãnilãè¿ãã«ã¯APIãå¤ãã¦ãã¡ã½ããå´ã§ã¯&outã¨&ãä»ãã¦è¿ããå¼ã³åºãå´ã§*gotã¨*ãä»ãã¦å¤ãåãåºãå¿ è¦ãã§ã¦ãã¾ãããï¼ãã¤ã³ã¿ãåç §ã使ã£ãã®ã¯å¤§å¦æ代ã«Cè¨èªãåå¼·ãã以æ¥ð¦ï¼ã
Goè¨èªã®å¦ã³ï¼ ãã¤ã³ã¿ï¼åç §ï¼ãè¿ãã«ã¯ &ãä»ãããã¢ãã¬ã¹ã§ã¯ãªãå¤ãåãåºãã«ã¯*ãä»ããã
å¼ã³åºãå ã§*ãä»ãã¦å¤ãåãåºãã¯æå³ããAPIã§ã¯ãªãã®ã§ããã¯æ¨ã¦ã¦ãæ¥ãéãæ»ãã¾ããåã®ãã¼ã¸ã§ã³ã«æ»ãã¦ããã¹ãã³ã¼ãããããã¯ã¯ã·ã§ã³ã³ã¼ãã¨ãã«è©¦è¡é¯èª¤ãããã¹ãã追å ãã¦æ¬¡ã«ãªãã¾ããã
æå¾ã«ãã¹ããã¿ã¼ã³ãå¢ãããçµæã次ã«ãªãã¾ãã
#TODO
gorename ã試ã# DONE
10,20ã®å ´å
1 => Iã®å¤æãã§ãããã¨ã
APIã®è¦ç´ãï¼ãªãã¸ã§ã¯ãæå風ã®ã¡ã½ããã«ç½®ãæãï¼
Goã§ããè¦ããããã¼ã¿é§ååã®ãã¹ãã«ç½®ãæã
2 => IIã®å¤æãã§ãããã¨ã
0ã®å ´åã4000ã®å ´åã¯ã¨ã©ã¼
4ã®å ´åã¯IV
9ã®å ´åã¯IX
5ã®å ´åã¯V
40ã®å ´å
50ã®å ´å
11ã®å ´åã¯XI
ããã
VSCodeã§ä¿åãããå³ãã¹ãå®è¡ã®æ¹æ³ãæ¢ã
ãã£ã¨ãgorenameã試ããã¨ãã¦å¿ãã¦ã¾ãããå¥ã®æ©ä¼ã«èª¿ã¹ã¦ã¿ããã¨æãã¾ãã
TDDã®ã«ã¿ã使ã£ã¦è¨èªãå¦ã¶çç±
2åã«æ¸¡ã£ã¦ãGoè¨èª ï¼ TDDã«ã¤ãã¦ç°¡åãªãé¡ã使ã£ã¦å¦ç¿éç¨ãè¨è¿°ãã¦ã¿ã¾ãããå®éã«ã¯ããã£ã¨å¤ãã®èª¿ã¹ç©ãããªããé²ãã¦ãã¾ãããçç¥ãã¦ãã¾ããï¼Goã®ãã¹ããã¬ã¼ã ã¯ã¼ã¯ã®ã³ã¼ãã軽ãè¦ããStackoverflowã§èª¿ã¹ããQiitaã®è¨äºãå¾å¾ãããWebãã¬ã¼ã ã¯ã¼ã¯ãªã©ã®ã©ã¤ãã©ãªã®ãã¹ããè¦ããããã«è¨è¼ããªãã£ãå¥ã®å®è£ æ¡ã試ããããï¼
ããã°ã©ãã³ã°ã¯ãç¥ããªãé ç®ãå¤æ°ãããªãï¼ã¤ï¼ã¤ç¢ºå®ã«ã¯ãªã¢ã«ãã¦å®éã«åããã®ãã¤ãã£ã¦ãããã©ã¤ï¼ã¨ã©ã¼ãå¿ è¦ãªä½æ¥ã§ãããã®ãã©ã¤ï¼ã¨ã©ã¼ã®éç¨ãæä¸æ¨¡ç´¢ã§éã«è¿·ããªãããã«å·¥å¤«ããæ¹æ³ã¨ãã¦ãTDDã¯ããã¤ãã®ã«ã¿ã示ãã¦ãã¾ãã
- åé¡ã®æ確åï¼ãã¹ããæ¸ããªãã¨ãããã¨ã¯ãåé¡å®ç¾©ï¼âä»æ§ï¼ã«ãªã«ãä¸æçãªãã¨ããããã¨ã®ãµã¤ã³ã§ãã
- ã´ã¼ã«ã®æ確åï¼ãã¹ããããã°âä½ãã§ããã°OKãâãæ確ã«ãããã¨ãã§ãã¾ãã
- ç°å¸¸ã®å³ææ¤ç¥ï¼å¾ããã®è¿½å ä¿®æ£ã§å£ãã¦ããªããã¨ãç´ãã«ç¢ºèªã§ãã¾ãã
- å®ç¾æ段ã®æ¢ç´¢ï¼ãªãã¡ã¯ã¿ãªã³ã°ã«ãã£ã¦ãâã©ãå®è£ ããã°OKãâã®å®ç¾æ¡ã模索ãã¾ãã
- é¸æè¢ã®åæï¼ãªãã¡ã¯ã¿ãªã³ã°ã1ç´ç·ã«ãçæ³ã®ããããªã³ã¼ãã«åãããã試è¡é¯èª¤ãããã¨ãããã§ããããå¹¾ã¤ããã£ã¨ãããã解決æ¡ã試ããï¼ã¤ã«åæããã¾ãããã¢ãããã¦ããã°å¯¾è©±ããªããããã£ã¨ããããæ¡ã«åæããããã¨ãã§ããã§ãããã
ããã«ãã¦ããJavaãRubyã°ãã触ã£ã¦ããåã«ã¨ã£ã¦ã¯ãGoè¨èªã¯ä¸æè°ãªããã°ã©ãã³ã°è¨èªã«æãã¾ãããä»ã®ããã°ã©ãã³ã°è¨èªã«ã¯ããè¨èªä»æ§ãè²ã åããã¦ãã¦ãéã«æ¸ ã ããã§ãã
ã³ã¼ãã®çµ±ä¸æãä¸ãã¦ãããèªåæ´å½¢ã¯ä¾¿å©ã§ãããIDEãªãã¦ã軽ãã¨ãã£ã¿æ¸ããã®ã¯å¬ããã¨ããã§ããRuby好ããªãåã¯è¦ããªãã®ããããã¾ããããåã«ã¨ã£ã¦ã¯ãã³ã¼ãã¸ã£ã³ããªã©ããããããä»äººã®ã³ã¼ããèªã¿ãããã§ããGoã使ã£ã¦ããå°ããDDDããã¤ã¯ããµã¼ãã¹ãªã©ã調ã¹ã¦è¡ãããã§ãã