Web+DB Press vol.82 㧠Go ã®ç¹éãæ¸ããã¦é ãã¾ãã #wdpress
update
- 2015/4/20: æè¡è©è«ç¤¾ããã®ãããã§ã ç¡æã§å ¬éããããã¨ã«ãªãã¾ããï¼
intro
ã¿ã¤ãã«ã®ã¨ããã Web+DB Press ã® vol.82 ã«
ãã¯ããã¦ã® Goã
ã¨ããã¿ã¤ãã«ã§ç¹éè¨äºãæ¸ããã¦ããã ãã¾ããã
Web+DB press vol.82 å±ãããç¹éã§ãã¯ããã¦ã® Goããæ
å½ããã¦ããã ãã¾ããã åè¦ããã¡ããããTour of Go ã®æ¬¡ããæ¢ãã¦ããæ¹ã®åèã«ãªãã°å¹¸ãã§ãï¼ #wdpress #golangjp pic.twitter.com/UbUue18wlp
— Jxck (@Jxck_) August 20, 2014
- ä½è : å±±å£å¾¹,Jxck,ä½ã æ¨å¤§è¼,横路é,å æ¥ç´ä¸,å±±æ¬ä¼¶,大平æ¦å¿,ç±³å·å¥ä¸,åæ¬ç»å²æ,è¥å祥æ£,åä¹ ç°é¾,å¹³æ éµå®,ä¼è¤ç´ä¹,ä½è¤å¤ªä¸,é«æ©ä¿å¹¸,æµ·éå¼æ,äºå¶å£®æ,ä½è¤æ©,åæç·ä¸é,æ©æ¬ç¿,èéç¥ä¸,ä¸å³¶è¡,渡éæµå¤ª,ã¯ã¾ã¡ã2,竹å,æ²³åå®æ,WEB+DB PRESSç·¨éé¨
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2014/08/23
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (1件) ãè¦ã
Web+DB ã« Go ãè¼ãã®ã¯ããããåãã¦ã ããã§ãï¼
Tour of Go ã®æ¬¡
ãã®ç¹éã¯ã Google ã® Go è¨èªã«ã¤ãã¦ãåå¿è ã対象ã«æ¸ãã¾ããã
Go ã«ã¯ Tour of Go ã¨ãããã¥ã¼ããªã¢ã«ãç¨æããã¦ããã æ°ãå½èªã«ç¿»è¨³ããã¦ãããããåå¿è ã¯ã¾ãããããå§ããã¨ãããã¿ã¼ã³ãå¤ãã¨æãã¾ãã
ãããããã®ãã¥ã¼ããªã¢ã«ã¯ããªãåæ©çãªé¨åã§çµãã£ã¦ãããããã®æ¬¡ã«ä½ãããããã¨ãªãã¨ã ããèªåã§ããã¥ã¡ã³ããèªã¿ãªãããã³ã¼ããæ¸ãã¦è¦ãããã¨ããæãã«ãªããè¥å¹²é£èºã大ããã¨ãããããã¾ããã
ããã¤ãããæ¸ç±ããã¡ãã£ã¨å¤ãå 容ã«ãªãã¤ã¤ããã¾ãã
ããã§ã Tour Of Go ã§ã¯ãã¾ãæ±ããã¦ããªããæ¨æºããã±ã¼ã¸ã®ä½¿ãæ¹ãããä¸æ©è¸ã¿è¾¼ãã interface ã®ä½¿ãæ¹ã並è¡å¦çã®èãæ¹ãªã©ãçãè¾¼ãã§ã
ãTour of Go ã®æ¬¡ã
ãæèãã¦æ¸ãã¾ããã
ãã¡ããæ¬èªã§åã㦠Go ãç¥ãããTour of Go ããã£ã¦ããªãæ¹ã§ã Go ãå§ããããããã«ãè¨èªã®ç´¹ä»ãç°å¢æ§ç¯ã«ã¤ãã¦ãæ¸ãã¦ãã¾ãã®ã§ãå®å¿ãã¦èªãã§ããã ããããã«æ¸ããã¦ããã ãã¾ããã
ä»åãç¹éãéãã¦ä½¿ç¨ãã Go ã®ãã¼ã¸ã§ã³ã¯å·çæç¹ã§ææ°ã® 1.3 ã§ãã
ç« ç«ã¦
ç« ç«ã¦ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ã(30 ãã¼ã¸ããã)ã
第1ç« ï¼Goè¨èªã®ç¹å¾´ã¨ç°å¢æ§ç¯ 第2ç« ï¼åºæ¬ææ³ ç¬¬3ç« ï¼åã·ã¹ãã 第4ç« ï¼æ¨æºããã±ã¼ã¸ 第5ç« :並è¡ããã°ã©ãã³ã°
å 容
1ç«
Goãçã¾ããèæ¯ããå ¨ä½çãªç¹å¾´ã«ã¤ãã¦è§¦ãã¦ãããGo ã®ç°å¢æ§ç¯æ¹æ³ã解説ãã¦ãã¾ãã åå¿è ããããããããç°å¢å¤æ° GOPATH ã«å§ã¾ãä¸é£ã®ããã¸ã§ã¯ãæ§æãããã«ãã®æ¹æ³ã Github ã¸ã®ããã±ã¼ã¸å ¬éã¾ã§ã§ããããã«ãªãã¾ãã
æè¿ä¸»æµã® GOPATH åºå®ã¹ã¿ã¤ã«ããã¯ãã¹ã³ã³ãã¤ã«ã®æºåæ¹æ³ãªã©ãã¡ãã£ã¨æ¢ãã¥ããæ å ±ã«ã¤ãã¦ãè¼ãã¦ãã¾ãã
2ç«
ã²ãããåºæ¬ææ³ã解説ãã¦ãã¾ãã Go ã®ææ³ä»æ§ã¯å²ã¨ã³ã³ãã¯ããªæ¹ã ã¨ã¯æãã¾ãããæ¸ãå§ããããã¼ã¸ãè¨ãã¿ãããããããããªãåã£ãã¨ããã¯ããããããã¾ãã
æ±ãåããªãã£ããã¨ã¯å¤ãããã¾ãããããã§ãåºæ¬çã«ããã«è¼ã£ã¦ãããã¨ãç¥ã£ã¦ããã°ãå ¬å¼ã®ããã¥ã¡ã³ããèªã¿é²ããããå ¬éããã¦ããã³ã¼ããçºããä¸ã§ã®ç¬¬ä¸æ©ã¨ã¯ãªãã¨æãã¾ãã
3ç«
ãã®ç« ã®ãã¼ãã¯åã§ãåå¤å±æ¹é¢ã®æ¹ã ãªã©ã«æ®´ãããããªè¡¨é¡ã«ãªã£ã¦ãã¾ãããå 容ã¯ããã£ã¦ã·ã³ãã«ã«ã Go ã® type ãã¼ã¯ã¼ãå¨è¾ºã®æ±ãã«ã¤ãã¦ã§ãã
struct ã interface ã®å®ç¾©ã使ãæ¹ãããåã®åãè¾¼ã¿(embed)ã type assertion ã type switch ã¨ãã£ãå 容ãã¾ã¨ãã¦ãã¾ãã ã¡ã¤ã³ã¯ææ³ã§ãããåã«ã¤ãã¦ã®å°éçãªå 容ã§ã¯ãªãã®ã§ãã容赦ãã ããã
4ç«
Tour of Go ã«è¶³ãã¦ãªããã¨ã®ä¸ã¤ãæ¨æºããã±ã¼ã¸ã®æ±ãã ã£ãã¨æã£ã¦ãã¾ãã Go ã¯æ¨æºããã±ã¼ã¸ãé常ã«å å®ãã¦ããã®ã§ããã®ãªãããè¯ã使ãã§ããã encoding/json, io, net/http, html/template ãªã©ãåãä¸ãã¦æ±ãã解説ãã æå¾ã¯ããããçµã¿åããã¦ç°¡åãªHTTPãµã¼ããä½æãã¾ãã
å®ã¯è£ãã¼ãã¨ãã¦ã io.Reader/io.Writer ã®æ±ããéè¦ãã¦ãã¾ãã ç¹ã«ãµã¼ãã®ãããªãã®ãæ¸ãå ´åããããã®çµã¿åããæ¹æ³ãç¥ã£ã¦ããã¨é常ã«å½¹ã«ç«ã¡ã¾ããã ããã¥ã¡ã³ããèªãã§ãããããã©ãçµã¿åããããããããããããã«ãªãã¨æãã¾ãã
5ç«
並è¡å¦çã Go ã®ç¹å¾´çãªé¨åãªã®ã§ã goroutine, channel, for-select, ãªã©ã使ã£ã¦ä¸¦è¡å¦çãããæ¹æ³ã¨ããã®èãæ¹ã®åºæ¬çãªé¨åãé ã追ã£ã¦è§£èª¬ãã¦ãã¾ãã
sync.WaitGroup ã«ããåæãã time.After() ã«ããã¤ãã³ãããããã¡ä»ã channel ã®æ±ããªã©ãæ±ã£ã¦ãããå¿ç¨ãããã¨ã§èªåãå¿ è¦ã¨ãã並è¡å¦çãçµãããã®åºç¤ã«ãªãã¨æãã¾ãã ãããããã®ç« ã¯ãµã³ãã«ã³ã¼ããã©ããã¦ã大ãããªããã¡ãªã®ã§ãåã£ããã®ãå¤ãããã¾ããã ããããå 㯠go concurrency ã§ã°ã°ãã°è ãã»ã©ã¹ã©ã¤ããåºã¦ããã®ã§ãããããèªãã¨è¯ããã¨æãã¾ãã
ãã¢å·ç
ãã¢ããã§ä½æ¥ãããæ¹ãè¯ãå ´åãå¤ãããã«ãå·çã1ã¤ã®ãã¼ãã¼ãã奪ãåã£ã¦è¡ãã¹ã¿ã¤ã«ã§ããã¨ã誤åè±åã«å¯¾ãã精度ãä¸ããããè¿·ãé¨åãããã«å ±æãã¦è°è«ã§ããããéä¸ãã§ãããããªã«ããæ°æé PC ã«åãã£ã¦ã¦ãé²æãã¼ãã¨ããç¶æ ãåé¿ã§ãã¦ããã®ã§ã¯ãã¨åã ããæã£ã¦ãã¾ããã
ããã§ã @inao ããããå·çã®è©±ãé ããã¨ãã«ã俺ã¨ãã¢å·çãã¦ããããªãããã¾ãï¼ãã¨èª¬å¾ã試ã¿ãã¨ãããã¡ãã£ã¨å¼·å¼ã§ã¯ããã¾ãããã 3, 4 åãã¢å·çãããæ©ä¼ãå¾ããããã¨ã«ãªãã¾ããã
ã¹ã¿ã¤ã«ã¨ãã¦ã¯ã俺ãå ã«ã©ãæ°å³ãª WIP å稿ãæ¸ãã¦ããããããäºäººã§æ ¡æ£ããªãããæ§æãè¨ãåããè¨æ³ã誤åè±åãè¦ã¦ããæãã§ãã ç·¨éè ã§ãã @inao ããã¨ä¸ç·ã«å·çããã°ã @inao ãããå¥éæ ¡æ£ã㦠gitlab 㧠issue ãç«ã¦ã¦ãããã¯ããã§ã¯ããã¾ãããï¼ãã¿ãããªããã¨ããããã³ã¹ããã ãã¶æ¸ãã ãããã俺ãæ¸ãã¦åããã«ããã¨ããããããã«ãããã§ã¯ããåãããªããã¨ææãã¦ãããã®ã§ãã¯ãã©ãã®ã§ã¯ç¡ããããã¨ããçãã§ãã
ãã¨åç´ã«ãã£ã¦ã¿ããã£ãã®ã§ã @inao ããç´ã ã«ä¿ºã®å®¶ã«æ¥ã¦ãããã1å°ã® Mac ãåã«ãã¢å·çã試ãã¦ã¿ã¾ããã
çµæã¨ãã¦ã @inao ããã¨ãã¢ã§æ ¡æ£ãããã¡ãªããã¯ãã£ãã¨æãã¾ãã 1ã¤ã®ç« ã®æ ¡æ£ãããããä¸æéãããã§çµãããããã¯æ ¡æ£ã¨ä¿®æ£ãå¥ã«ãªã£ãæã®ãã¼ã¿ã«ã³ã¹ãã¨ã俺ãä¿®æ£ãããµããã¦æãã Twitter ããããããéãã¦ãã¾ããªã¹ã¯ãéããªãã¼ãã«ã§ããã®ã§è¯ãã£ãã¨æãã¾ãã
ããããæ ¡æ£ã¾ã§ã® Go ã®è§£èª¬å稿ãæ¸ãé¨åã«ã¤ãã¦ã¯ããã£ã±ã俺ãå ã«ç¨æããªãã¨ãããªãã®ã§ãããããã®ç¨æããã¾ãé²ã¾ããçµæçã«ä¿ºãã§ãã¦ãªãç¾è¡ãæ¸ãã¦ãã®ãã俺ã®é£ã§ç¨²å°¾ãããç£è¦ããã¨ããæãã«ãªã£ã¦ãã¾ããæçµçã«ã¯ããã£ã±ããã¾ãå¹æåºã¦ãªãããã¨ãããã¨ã§æ®éã®ã¹ã¿ã¤ã«ã«åã¾ã£ã¦ãã£ã¦ãã¾ãã¾ããã
俺ããããããå稿é¨åã®ä½æ¥ãåãã£ã¦ãããã°ãããªãå¹çããæ ¡æ£é²ããããããããªãããªã¨æãã¾ããå稿é¨åãã¾ãå¥ã®äººã¨ãã¢å·çããã¨ããã®ãé¢ç½ãã£ãããã ã¨ããããããå°ããã¾ãããããã¨ããåçã¨ã¨ãã«ãæªãã¯ãªããªã¨æãã¾ããã
ãã¨ãæ¯åçµãã£ãå¾ @inao ããã¨ã飯ãé£ã¹ã«ãã£ã¦ãè²ã ãªè©±ãããã®ã楽ããã£ãã§ãã ããã§ã®ããåãã¯ãå æ¥å ¬éãã #mozaicfm ã® REST ã®å ã«ãæ¿ãå½±é¿ãã¦ããããã¾ãw
è¬è¾
Web+DB ã¯ããã§ä¸åç®ã§ããããªãã©ãã£ã¦ãå·çã¯ãªããªãé£ããã§ãããã
ãããªä¸ã§ãã俺ã®ããã¾ã¾ã«ã¤ããã£ã¦ä»äºçµããã«ä¿ºã®å®¶ã¾ã§ãã¢ãããã«æ¥ã¦ããã @inao ããã«ã¯æ¬å½ã«æè¬ãã¦ãã¾ãã楽ããã£ãã§ãï¼
çãæ¢ã¾ã£ã¦ãé ã«ãå宿æ社ã§è¡ãããé»ã ä¼ã§ããã®å ´ãã³ãºãªã³ããããã¦ããã£ããããã§ãããããã®ã¾ã¾ 4, 5 ç« ã®ååã«ãªãã¾ããã @hokaccha ããã @yosuke_furukawa ããã @sugyan ãããããã¨ããããã¾ããã
ããã¦ã æããã«ãã¦ãã¨ããã俺ã«ã¤ãã¾ã£ã¦ 大äºãªä¼æ¥ã空ãã¦ãã¤ãã£ããã§ã¬ãã¥ã¼ãã¦ããã @tenntenn ã«ã¯æè¬ãã¦ã¾ãããããæ¿ãè°è«ãã§ãããã楽ããã£ãã
æ¸ãç©æ¥ã¯ãè ¹ãã£ã±ããªã®ã§ããã°ããã¯ã³ã¼ãæ¸ãæ¹ã«å°å¿µãããã§ãã