Go
ããã¯ããªã«ãããããŠæžãããã®ïŒ Go 1.16ã§ãembedãšããããã±ãŒãžïŒæ©èœïŒãè¿œå ããããããªã®ã§ããã¡ããè©ŠããŠã¿ãããªãšæããŸããŠã ãã«ãæã«ãã¡ã€ã«ãåã蟌ã¿ãã¢ããªã±ãŒã·ã§ã³ã®å®è¡æã«ã¢ã¯ã»ã¹ã§ããæ©èœã®ããã§ãã embed Go 1.16ã®âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã䜿ã£ãŠãããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ããã³ãŒããæžããŠã¿ãããªããšæããŸããŠã sqlããã±ãŒãž Goã§ããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ããã«ã¯ãsqlããã±ãŒãžã䜿ãããã§ãã sql - The Go Programming Language sqlããã±ãŒãžâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã§ãã¹ããåããããããŠãããšããããªæãã§cachedãšè¡šç€ºããããããŸãã $ go test ./... ok xxxx (cached) ãã¹ãçµæããã£ãã·ã¥ãããŠããããã§ãã ããã«ã€ããŠãã¡ãã£ãšèª¿ã¹ãŠã¿ãŸããã ç°å¢ ä»åã®ç°âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã®æ§é äœã®åæåæ¹æ³ã¯ãããããããŸãããã©ããã©ãéããã ã£ãïŒãšããã®ãããå¿ããã®ã§ã¡ã¢ããŠãããŸãã ç°å¢ ä»åã®ç°å¢ã¯ããã¡ãã§ãã $ go version go version go1.16 linux/amd64 確èªçšã®ã¢ãžã¥ãŒã«âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ èšäºãæžç±ãªã©ã§ã以äžã®ãããªèšè¿°ãèŠãããŸãã $ go build -ldflags '-X main.xxxx=....' ãã®-ldflagsãš-Xã®æå®ã§ããã°ã©ã å ã®å€ãå€ããŠãããããªã®ã§ããããå€ããããŸãããšããæ å ±ä»¥å€ã®ããšã ããŸãèŠâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã®ãšã©ãŒåŠçã«é¢ããæ å ±ãèŠãŠãããšxerrorsãšãããã®ãããåºãŠããã®ã§ã1床èŠãŠãããããªãšæããŸããŠã xerrorsããã±ãŒãž xerrorsããã±ãŒãžã¯ãGoã®ãšã©ãŒãã³ããªã³ã°ã®ããã®ããã±ãŒãžã§ãã xerrors · pâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã¯aptïŒïŒPPAïŒã§ã€ã³ã¹ããŒã«ããŠããã®ã§ãããä»ã®ããŒãžã§ã³ã䜿ããããªãæããã£ããããŸãã Ubuntu · golang/go Wiki · GitHub ããããæã¯ã©ããããããã®ããªïŒãšæã£ãã®ã§ãããGoèªäœãè€æ°ããŒãžã§ã³âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã§æžãããã¢ããªã±ãŒã·ã§ã³ããããã°ããæ¹æ³ããæŒãããŠãããããªããšæããŸããŠã Goã¢ããªã±ãŒã·ã§ã³ã®ãããã° Goã®ããã¥ã¡ã³ãã§ãããã°ã«ã€ããŠæžãããŠããã®ã¯ããã¡ãã®ããŒãžã§ãã Debugging Go CodeâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã§ã®ãã«ãããŒã«ã¯ãmakeã䜿ãããšãå€ããšèããã®ã§ã ããã€ããGoã§æžãããæåãªOSSãèŠãŠã¿ããšã確ãã«Makefileã眮ãããŠããŸãã https://github.com/prometheus/prometheus/blob/v2.24.1/Makefile https:âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã®æ¬ãèªãã ãããµã³ãã«ã³ãŒããèŠãŠããããããšãããããã®ãç®ã«ããã®ã§ããã file, err = os.Create(filename) if err == nil { return } nilãã©ããã®å€å®ã¯ããŠããâŠã ãšã©ãŒã®äžèº«ãçš®é¡ã«èžã¿èŸŒã¿ããâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ ããã°ã©ã ãæžãæã«ãGoã®ãœãŒã¹ã³ãŒããã©ã€ãã©ãªã®ãœãŒã¹ã³ãŒããèŠã€ã€ãããã䜿ã£ããããã®ããªïŒããšäœ¿ãããšãããš ã¢ã¯ã»ã¹ã§ããªãããšãšããããã ããããã°ãGoã®ã¹ã³ãŒãçãªè©±ãç¥ããªãã§ãããç¹ã«âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã§ããã°ã©ã ãæžããŠããŠãããã®å€æ°ã®åã¯ãªã«ïŒãã¿ãããªæã«ã©ããã£ãŠåã®æ å ±ãååŸãããã§ããã£ãïŒãšããããšã§ã ä»ã®åæ©ã¯ããããã°æãšãã«åã®ååãç¥ãããããããã§ãã fmtããã±ãŒãžã®%TæžåŒâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ ãã¡ãã®ãšã³ããªã§ãGoã§æžããã¢ããªã±ãŒã·ã§ã³ã«å«ãŸããã¢ãžã¥ãŒã«ãªã©ããããã ãããïŒãšãã確èªãããŸããã go tool nmã³ãã³ãã§ãGoã®å®è¡å¯èœãã¡ã€ã«ã®å®çŸ©ãã·ã³ãã«ã衚瀺ãã - CLOVER 次ã¯ã䜿çšããŠâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã§äœã£ãã¢ããªã±ãŒã·ã§ã³ã«å«ãŸããã©ã€ãã©ãªãšãã®æ å ±ã£ãŠãããã®ããªïŒãšæã£ãŠèª¿ã¹ãŠã¿ãã®ã§ãããã³ãã³ãã ããããã§ãã go tool nmãšããã³ãã³ããè¿ãæãã§ããã nm - The Go Programming Language âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã®ãã³ãã¬ãŒããšã³ãžã³ã調ã¹ãŠã¿ããããªãšæã£ãã®ã§ãããæšæºã©ã€ãã©ãªã«ãããããªã®ã§ããã¡ããè©Šã㊠ã¿ãããšã«ããŸããã Goã®æšæºã©ã€ãã©ãªã«ãããã³ãã¬ãŒããšã³ãžã³ text/templateãšãhtml/templateâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã®å匷ã«ãšããããšã§ãEcho ServerãClientãæžããŠã¿ããããªãšã ãé¡ Goã䜿ã£ãŠãEcho ServerãšClientãããããæžããŠãããŸãã Echo Server åŒæ°ã§ãã€ã³ãããã¢ãã¬ã¹ãšããŒããåãåã æå®ããªãå Žåã¯0.âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã®å匷ãããŠããŠãã¡ãœããã®ã¬ã·ãŒããŒå®çŸ©ã2ã€ãã£ãŠãã©ããã䜿ãåãããããããã®ãããããããªãã£ãã®ã§ 調ã¹ãŠã¿ãããšã«ããŸããã 2ã€ããšããã®ã¯ãããããã®ãš func (p Point) Length() float64 { âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã§äœ¿ãç°å¢å€æ°ãç¥ããããªãšæã£ãã®ã§ãããgoã³ãã³ããèŠãŠããŠenvãšããã³ãã³ããããã®ã«æ°ã¥ãã å°ãèŠãŠã¿ããããªããšã ç°å¢ ä»åã®ç°å¢ã¯ããã¡ãã§ãã $ go version go version go1.15.6 linux/amd64 âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã«ããããã¢ãµãŒã·ã§ã³ãªã©ã®æ©èœãæäŸããtestifyãšããã©ã€ãã©ãªãããã®ãç¥ããŸããŠã ãã¡ããå°ãè©ŠããŠãããããªããšã testify testifyã¯ã以äžã®æ©èœãæäŸããã©ã€ãã©ãªã§ãã ã¢ãµãŒã·ã§ã³ ã¢ã㯠ãâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã§ã®ãã¹ãã®æžãæ¹ãåŠãã§ã¿ããããªãšã Goã«ã¯ãã¹ãã®ä»çµã¿ãæšæºã§çµã¿èŸŒãŸããŠããŠãgo testã³ãã³ããštestingããã±ãŒãžã䜿ãã¿ããã§ãã testing - The Go Programming Language ç°å¢ ä»åã®ç°å¢ã¯ããã¡âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã䜿ã£ãããã°ã©ã ãæžããŠããããšæãã®ã§ãããã¢ãžã¥ãŒã«ã«é¢ããæ å ±ãå šç¶ç¥ããªãã®ã§ãè©ŠããªããåŠã㧠ã¿ãããšã ããã°ã©ã ãæžããŠããããããã±ãŒãžãããã¯äœ¿ãã§ãããããšã ãªããããã§è©Šãæ¡ä»¶âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Goã§æžãããœãŒã¹ã³ãŒããããã£ã¬ã¯ããªå ãååž°çã«ãã©ãŒãããããããšããããšã§ã ã©ãããgofmtãšgo fmtã䜿ãå Žåã§éãããã§ãã ä»åã¯ãã«ã¬ã³ããã£ã¬ã¯ããªïŒ.ïŒã«èããŸãã ç°å¢ ä»åã®ç°å¢ã¯ããã¡ãã§âŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ ãããããå°ããã€Goãæ±ã£ãŠã¿ããããªããšæããŸããŠã The Go Programming Language 觊ã£ãããšããªãã®ã§ãä»åã¯ãšããããç°¡åã«ã€ã³ã¹ããŒãšãšãã£ã¿ã®èšå®ãããããããŸãã ç°å¢ ä»åã®ç°å¢ã¯ããã¡ãã§ããUâŠ
ããã¯ããªã«ãããããŠæžãããã®ïŒ Vegetaãšãããå²ãšåæ§çãªè² è·ãã¹ãããŒã«ããããã³ãã³ãã©ã€ã³ã§ç°¡åã«äœ¿ããããªã®ã§è©ŠããŠã¿ããããšããããšã§ã GitHub - tsenart/vegeta: HTTP load testing tool and library. It's over 9000! Apache BenchâŠ
ã¡ãã£ãšãã調ã¹ç©ãããŠããããCaddyãšããGo補ã®WebãµãŒããŒã䟿å©ã ãšããããšãç¥ããŸããŠãCaddyCADDYã§æ軜ã«HTTP/2ãµãŒããç«ãŠã - yuw27bâs blogCaddy 㧠HTTP/2 ãš php-fpm ãå©çšãã - Qiita CaddyïŒ Goã§å®è£ ãããWebãµãŒããŒã ããã§ããCaâŠ