Merpay Advent Calendar 2019 ã®22æ¥ç®ã¯ãã¡ã«ãã¤ã¹ãã¼ãæããã¼ã /Backend Engineer ã® @oinume ããéããã¾ããä»æ¥ã¯ã³ã¼ãã¬ãã¥ã¼ã«ã¤ãã¦èªåãæ®æ®µããå®è·µãã¦ãããã¨ãæ¸ãã¦ã¿ããã¨æãã¾ãã
ã¯ããã«
ä¸ã®ä¸ã«ã¯ã³ã¼ãã¬ãã¥ã¼ãããæã®è¦³ç¹ã«ã¤ãã¦ã¯æ°å¤ãå ±æããã¦ãã¾ãããããè¯ãã³ã¼ãã¬ãã¥ã¼ãããããã«ã¯ã©ãããã®ãè¯ãããã¨ããHOWã«ã¤ãã¦ã®ãã¦ãã¦ã¯ãã¾ãã·ã§ã¢ããã¦ããªããããªæ°ããã¦ãã¾ãããã®ãããä»æ¥ã¯èªåãªãã«å¿ããã¦ããã³ã¼ãã¬ãã¥ã¼ã®ããæ¹ã¨ãã¤ãã§ã«æ°ãã¤ãã¦ãã観ç¹ã«ã¤ãã¦æ¸ãããã¨æãã¾ãã
Slackãéãã
(ãããæ¬å½ã«ä¸çªå¤§äºã ã¨æã£ã¦ããã®ã§æåã«æã£ã¦ããã®ã§ãã)ç§ã¯æ¥µç«¯ã«éä¸åããªããããSlackã®Desktopéç¥ãæ¥ãã¨ã¤ãã¤ããããæ°ã«ãªã£ã¦è¦ã¦ãã¾ãã¾ããã³ã¼ãã¬ãã¥ã¼ã®æã¯éä¸ãããã¨ã大äºãªã®ã§ãSlackãéãã¦éä¸ã§ããç°å¢ãä½ã£ã¦ãã¾ãã
WHATãWHYããã¡ãã¨æ¸ãã¦ããã
typoãç´ããããªåç´ãªãã®ã§ããã°è©±ã¯å¥ã§ããããã¡ãã¨ããã³ã¼ãã¬ãã¥ã¼ãããããã«ã¯
- ãã®å¤æ´ã§ä½ãå¤ããã®ã
- ãªãå¤ããå¿ è¦ãããã®ã
ãç解ããå¿ è¦ãããã¾ããã§ãã®ã§ãPull requestã®èª¬æã«ã¯å¤æ´å 容ã¨ãªããã®å¤æ´ãããã®ããæè¨ãã¦ããã£ã¦ãã¾ããä¾ãã°ããã°ä¿®æ£ãã¨ãã説æã ãã§ã¯ãã©ããããã°ããã£ãã®ãããã®ãã°ãã©ãããå½±é¿ãä¸ãã¦ããã®ãã¯ãããã¾ãããã³ã¼ãã¬ãã¥ã¼ã®åªå 度ã»éè¦åº¦ãå¤æããããã«ããã®ãããªæ å ±ã¯å¤§äºã ã¨æã£ã¦ãã¾ãã
ã³ã¼ããèªåã®PCã«pullãã¦IDEã§è¦ã
ããå¹ççãã¤è³ªã®é«ãã¬ãã¥ã¼ãè¡ãããã«ãèªåã®PCã«ã³ã¼ããpullãã¦IDEã§ã³ã¼ããè¦ã¦ãã¾ããçç±ã¨ãã¦ã¯â¦
- ã³ã¼ãã¸ã£ã³ãã使ãã
- IDEãã¨ãã£ã¿ã®æ©è½ã§warningãè¦ã¤ãããã
- IDEã¾ãã¯ã¿ã¼ããã«ããå®è¡ã§ãã
ã«ãªãã¾ãã詳ããã¯å¾è¿°ãã¾ããã大ããªPull requestã®å ´åã¯å ¨ä½åãææ¡ããããã«ãç¹ã«ã³ã¼ãã¸ã£ã³ãã¯æç¨ã ã¨æã£ã¦ãã¾ãã
CIã§lintãããã
ãã¤ã³ãã³ãã¯ã¹ãã¼ã¹ã§ã¯ãªãã¿ãã«ãã¦ä¸ãããã¨ãããããªä¸æ¯ãªããåãããªããããã«ãgofmtãlintãæå¹æ´»ç¨ããã¨ãããæ¬è³ªçãªã³ã¼ãã¬ãã¥ã¼ã«éä¸ã§ããã¨æã£ã¦ãã¾ããGoã§ããã°gofmtããããã®ã¯å½ç¶ã§ãããç§ã®æ å½ããã¸ã§ã¯ãã§ã¯golangci-lintã使ã£ã¦ä¸»ã«ä»¥ä¸ã®lintãããã¦ãã¾ãã
- goimports
- govet
- errcheck
- staticcheck
- unused
ã¾ããSpannerã使ã£ã¦ããã®ã§ReadOnlyTransactionã®Closeå¿ããªã©ãè¦åãã¦ãããzaganeãæè¿å°å ¥ããã¾ãããGoã§ã¯éç解æãã¼ã«ãå å®ãã¦ãããããã³ã³ãã¥ã¼ã¿ã¼ã«ã§ãããã¨ã¯ã©ãã©ãä»»ãã¦ããã®ãããã¨æãã¾ãã
å ¨ä½åãææ¡ãã
A->B->C->D ã¨ããé¢æ°å¼ã³åºãã®æ§é ã«ãªã£ã¦ãã¦ãD
ã®ã³ã¼ãã®æ·±ãã¨ãããä¿®æ£ããã¦ããå ´åã¯ããã®ä¿®æ£ãã©ãããå½±é¿ãåã¼ãã®ããå¼ã³åºãå
ãè¤æ°ãã£ãå ´åã«æ¬å½ã«ãã®ä¿®æ£ã§å
¨ã¦åé¡ãªãã®ãã確èªããå¿
è¦ãããã¾ãããã®ãããç§ã¯ä»¥ä¸ã®é çªã§ã³ã¼ããèªã¿é²ãã¦è¡ããã¨ãå¤ãã§ãã
- Dã®é¨åã§å ·ä½çã«ä¿®æ£ãããå 容ãææ¡ãã
- ä¿®æ£ãããç®æãå¼ã³åºãããAPIã®å ¥ãå£ã調ã¹ã(Aã®é¨å)
- å ¥ãå£ããã³ã¼ããèªã¿ã¤ã¤å¾ã ã«æ·±ãæ½ã£ã¦ãããä¿®æ£ãããç®æãããããã¦è¦ã
- ã¦ããããã¹ããªã©ã®ã³ã¼ããè¦ã¦ä¸è¶³ãã¦ãããã¤ã³ãããªãããè¦ã
- Dã«é¢ããé¨åã§ä»ã«å½±é¿ããªãããè¦ã
大ããªä¿®æ£ã®å ¨ä½åãææ¡ãã
ã¾ãã大ããªPull requestã®å ´åã¯å ¨ä½åãææ¡ãããã¨ãããå°é£ã§ããä¿®æ£å 容ã«ãããã¾ãããä¿®æ£ç¯å²ã大ããå ´åã¯ãä¿®æ£åã®ã½ã¼ã¹ã³ã¼ãã§é¢é£ããé¨åããAPIã®å ¥ãå£ãã丸ãã¨èªãã§ãã£ã¨ææ¡ãããã¨ã大äºã ã¨æã£ã¦ãã¾ãããã®ä¸ã§ä¿®æ£ãããå 容ãã©ããããã¨ãªã®ããææ¡ããä¿®æ£æ¼ãã¯ãªãããªã©ã®èª¿æ»ãè¡ãã¾ãã
panicãå ¥ãã¦ãã¹ããå ¨ã¦å®è¡ãã
ãã®é¢æ°ã¯å ¥ãå£ãå«ãã¦ã©ãããå¼ã°ãã¦ããã®ãï¼ã¨ãããã¨ãã½ã¼ã¹ã³ã¼ãã ãã§èª¿ã¹ããã¨ã¯ãªããªãé£ããã§ãããã®ãããä¿®æ£ç®æã«panicãä»è¾¼ãã§å ¨ã¦ã®ãã¹ããå®è¡ãã失æãããã¹ããçºãã¦ããªãã»ã©ãã®ä¿®æ£ã¯ãããªã¨ããã«ãå½±é¿ãããã®ããã¨ãããã¨ã調ã¹ãããã¾ãã
å®è¡æã®ç¶æ ææ¡ã®ããã«ãããã¬ã使ã
ä¿®æ£ç®æãå®è¡ãããæã«ã使ããã¦ããå¤æ°ãå¤ãã¨ãããã«ã©ãããå¤ãå ¥ã£ã¦ããããç¥ããã¨ãé£ããã§ããããããå ´åã¯ãããã¬ã使ãã¾ãããããããã¬ã使ããã¨ã§å ·ä½çãªå¤æ°ã®ä¸èº«ãç¥ããã¨ãã§ãããããã³ã¼ããèªãæã®å©ãã«ãªãã¾ãããã¡ããå¤æ°åãããããããã«è¶ãããã¨ã¯ããã¾ããã…
大ããããPull requestã¯åå²ãã¦ããã
å½ããåã§ãã大ããããPull requestã¯ã³ã¼ãã¬ãã¥ã¼ã大å¤ã§ãã大ããªæ©è½ã§ãã¤ãããæ¢åã®ã³ã¼ãã«å½±é¿ãä¸ããå ´åã¯ãç°å¢å¤æ°ãªã©ã使ã£ã¦feature toggleã§ããããã«ãã¦ãåå²ãã¦PRãåºãããã«ãé¡ããã¦ãã¾ããããã¯ã³ã¼ãã¬ãã¥ã¼ã楽ã«ãªãã ãã§ã¯ãªããä»ã®Pull requestã¨ã³ã³ããªã¯ããã«ãããªãã¨ããã¡ãªãããããã¾ãã
éå»ã®çµç·¯ã調ã¹ã
ã³ã¼ãã¬ãã¥ã¼ããã¦ããæã«ããªããã¨ãã¨ããããå®è£ ã«ãªã£ã¦ããã®ãï¼ãã¨ããçåãçãããã¨ãããã¾ãããã®ãããªå ´åã¯ä»¥ä¸ã®æµãã§çµç·¯ã調ã¹ã¦ãã¾ãããã ããéå»ã®Pull requestã«ã¡ããã¨ãã®ä¿®æ£ã®ç®ç(WHAT)ãçç±(WHY)ãæ¸ããã¦ãããã¨ãåæã¨ãªãã®ã§ãå ã»ã©ç´¹ä»ãããããªPull requestã®èª¬æããã¡ãã¨æ¸ãã¨ãããã¨ã大äºã§ãã
- IntelliJã®Open on GitHubã®æ©è½ã使ã£ã¦ãIDEã®ã¨ãã£ã¿ããGitHubãéã
- GitHubã§Blameãã¦ä¿®æ£ãããã³ããããPull requestã調ã¹ã
- Pull requestã«ããWHATãWHYã確èªãã
ããããªããã°è³ªåãã
ã©ããªã«ã³ã¼ããä»æ§ãèªãã§ãããããªããã¨ã¯ããã®ã¯å½ããåãªã®ã§ãç§ã¯å²ã¨æ°è»½ã«è³ªåããã¦ãã¾ããããããæå³ã§ã¯æ°è»½ã«è³ªåã§ããé°å²æ°ãæ®æ®µããä½ã£ã¦ãããã¨ã¯ã¨ã¦ã大äºã ã¨æã£ã¦ãã¾ããããããå¿ççå®å ¨æ§ã¨ãããã®ã§ããã
ã¾ããèªåãPull requestãåºãæã«ãããã¯æå³ããããã¥ããããªãã¨æãæã¯ãã³ã¼ãã®ä¸ã«ã³ã¡ã³ããæ¸ããããPull requestã«èªåã§è£è¶³ã³ã¡ã³ããå ¥ããããã¾ãã
ã¬ãã¥ã¼æã«ç¹ã«æ°ãã¤ãã¦ãããã¨
ã³ã¼ãã¬ãã¥ã¼ã®è¦³ç¹ã«ã¤ãã¦ãä½µãã¦æ¸ãã¦ããã¾ããé·ããªãã®ã§éè¦ãª2ã¤ã ãããã¯ã¢ãããã¦ãã¾ãã
APIãåªçã«ãªã£ã¦ãããï¼
ã¡ã«ãã¤ã§ã¯microserviceã®APIãä½ãæã«åªçã«ãªã£ã¦ãããã©ãããéè¦ãã¦ãã¾ããæå¤ã¨ãããå¿ãã¦å®è£
ãã¦ããããåªçã«ããã¤ãããå®ã¯ãªã£ã¦ããªãã£ãã¨ãããããªã±ã¼ã¹ãããã®ã§ãAPIãåªçã«ãªã£ã¦ããããAPIã2åå®è¡ãã¦åªçã«ãªã£ã¦ãããããã¹ãããã³ã¼ããããããã³ã¼ãã¬ãã¥ã¼ã§è¦ã¦ãã¾ãã
ã¾ããæ¢åã®APIã«å¦çã追å ãããã¨ã§ããã¨ãã¨åªçã§ãã£ããã®ãåªçã§ãªããªã£ã¦ãã¾ãã¨ãããã¨ãããã®ã§ãåªçã«ãªã£ã¦ãããã®ãã¹ããæ¸ãã¦ãããã¨ã大äºã§ãã
å½±é¿ç¯å²ã®èª¿æ»ãã§ãã¦ããã
- structã«ä½ããã£ã¼ã«ãã追å ããã
- statusã®ãããªenumã«æ°ããé ç®ã追å ããã
ä¸è¨ã®ãããªå ´åã¯ãä¿®æ£æ¼ãããªãããã¬ãã¥ã¼ã¯ã¼ã¨ãã¦ãã§ãã¯ãã¦ãã¾ãããã¨ãã¨ãå½±é¿ç¯å²ã®èª¿æ»ãè¡ãã®ã¯ã³ã¼ããæ¸ãã人ã®ç¾©åãã ã¨æã£ã¦ãã¦ãã®ãããªãã¨ã¯ãã£ã¦ãã¾ããã§ããããæå¤ã¨ãããæ¼ãã¦ããã±ã¼ã¹ãå¤ãããã§ããã¾ããããã§åé¡ãææã§ããã¨ã¬ãã¥ã¼ãããå´ãããæè¬ããããã¨ãå¤ãã§ãã
æå¾ã«
èªåãæ®æ®µè¡ã£ã¦ããã³ã¼ãã¬ãã¥ã¼ã«ã¤ãã¦ã¤ãã¤ãã¨æ¸ãã¦ã¿ã¾ããããèªåã¯ãããªããæ¹ããã¦ãããããªã©ãããã°ããã²Twitterãªã©ã§ã·ã§ã¢ãã¦ããããã¨å¬ããã§ãã
ææ¥ã®Merpay Advent Calendar å·çæ å½ã¯ã Backend Engineer ã® @kokukuma ããã§ããå¼ãç¶ãã楽ãã¿ãã ããã