ã¹ã¿ãã£ãµããªã§ã½ããã¦ã§ã¢ã¨ã³ã¸ãã¢ãã¨ã³ã¸ãã¢ãªã³ã°ããã¼ã¸ã£ããã£ã¦ãã @pankona ã§ãã
Go 1.24 ã§ãã¼ã«ã®ãã¼ã¸ã§ã³ç®¡çã便å©ã«ãªãããã¨ãã話ããã¾ãã
(Go 1.23 ç¾å¨) go install
ã¨ãã便å©ãªã³ãã³ãããã
Go 1.24 ã®è©±ãããåã«ãgo install
ã¨ããã³ãã³ãã®ç¾ç¶ã«ã¤ãã¦ç°¡åã«è§¦ãã¦ããã¾ãã
Go ã§æ¸ããããã¼ã«ã®ãã¡ãæå®ã®æ¡ä»¶ãæºãããã®ã¯ go install
ã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãããã¨ãã§ãã¾ãããã¨ãã° goimports ã§ããã°ã
go install golang.org/x/tools/cmd/goimports@latest
ã¨ããã³ãã³ããå®è¡ãããã¨ã§æã ã®PCã«ã¤ã³ã¹ãã¼ã«ããã使ããã¨ãã§ããããã«ãªãã¾ããããã¸ãç°¡åã§ä¾¿å©ã§ãã
ã¤ã³ã¹ãã¼ã«ãããã¼ã«ã®ãã¼ã¸ã§ã³ãæå®ãããå ´åã¯ã©ã®ããã«ããã°ããã§ããããããã¼ã¸ã§ã³ã¯æ«å°¾ã®ã¢ãããã¼ã¯ããå¾ã®é¨åã§æå®ãããã¨ãã§ãã¾ãããã¨ãã°ã³ãã³ããå®è¡ããæç¹ã§ã®ææ°ãã¼ã¸ã§ã³ãå
¥æããããã°ãå
è¿°ã®ã³ãã³ãã®ããã«æ«å°¾ã« @latest
ãã¤ãã¾ããææ°ãã¼ã¸ã§ã³ã§ã¯ãªãææã®ãã¼ã¸ã§ã³ãæå®ãããå ´åã¯ã@v1.2.3
ã®ããã«é©å½ãªãã¼ã¸ã§ã³ãæå®ãããã¨ãã§ãã¾ã (ãã¼ã¸ã§ã³ã示ãå¤ã¨ãã¦ãã³ãããããã·ã¥ããã©ã³ããã¿ã°ãªã©ãæå®ã§ãã¾ã) ã
go install
ã§å°å
¥ãããã¼ã«ã®ãã¼ã¸ã§ã³ã¯ go.mod ã§ç®¡çãã¦ããããªãã¦ä¸ä¾¿
ã¨ããã§ãrenovate1 ã dependabot2 ã¨ãããããã¯ãããåç¥ã§ãããããrenovate ã dependabot ã¯ãæã ãä½ã£ã¦ããã½ããã¦ã§ã¢ãä¾åãã¦ããã©ã¤ãã©ãªã«ã¤ãã¦ãæ°ãããã¼ã¸ã§ã³ããªãªã¼ã¹ããã¦ãããèªåçã«ãã«ãªã¯ã¨ã¹ããä½ããã©ã¤ãã©ãªã®æ´æ°ããµãã¼ããã¦ããã¾ããrenovate ã dependabot 㯠Go ããµãã¼ããã¦ãã¦ãgo.mod (å Go ããã¸ã§ã¯ãã§ç¨ãããã¦ããä¾åã©ã¤ãã©ãªãè¨è¼ããã¦ãããã¡ã¤ã«) ã®è¨è¼å 容ãå ã«ãã¦ã©ã¤ãã©ãªæ´æ°ã®ããã®ãã«ãªã¯ã¨ã¹ããä½ã£ã¦ããã¾ãã
ãã¦ãgo install
ã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãããã¼ã«ã«é¢ãã¦ããä¾åã©ã¤ãã©ãªã¨åæ§ã«æ°ãããã¼ã¸ã§ã³ãåºãããã¼ã¸ã§ã³ãæ´æ°ãããã«ãªã¯ã¨ã¹ããåºãã¦ããããã¨ä¾¿å©ã§ããããã go install
ã³ãã³ãã§å°å
¥ãããã¼ã«ã«ã¤ãã¦ã¯ go.mod ã«ãã¼ã¸ã§ã³ãåºæ¬çã«ã¯æ¸ããã¾ããããã㯠go.mod ã¯ããã¾ã§å Go ããã¸ã§ã¯ãã®ãã«ããè¡ãããã«å¿
è¦ãªã©ã¤ãã©ãªã®ãã¼ã¸ã§ã³ãè¨è¼ããããã®å ´æã§ããããã«ãã«ç´æ¥é¢ããã®ãªããã¼ã«é¢é£ã®è¨è¼ã¯æçµçã«ã¯æ¶ãã¦ãã¾ããã¨ãçç±ã§ã (go mod tidy ãããã¨ãã«æ¶ãã¾ã) ãnpm ã§è¨ãã¨ããã® devDependencies ã®ä»çµã¿ã go.mod ã«ã¯ãªãã¨ãããã¨ã§ãã
tools.go ã使ãã¨ããã¢ããã¼ã
ããã§ãtools.go (ã®ãããªä½ããã®ãã¡ã¤ã«) ãç¨ã㦠go mod tidy ãã¦ããã¼ã«ã®ä¾åã go.mod ããæ¶ãããªãããã«ããã¢ããã¼ããå ¬å¼ Wiki ã§ç´¹ä»ããã¦ãã¾ãã
å½è©² Wiki ã§ã¯ãããã©ã³ã¯ã¤ã³ãã¼ãããç¨ãããã¯ããã¯ãç´¹ä»ããã¦ãã¾ãããã©ã³ã¯ã¤ã³ãã¼ãã¨ã¯ã以ä¸ã®ãããªå½¢å¼ã®ã¤ã³ãã¼ãæãæãã¾ããä¸è¨ã®ä¾ã§ã¯ golang.org/x/tools/cmd/goimports
ããã©ã³ã¯ã¤ã³ãã¼ããã¦ãã¾ãã
package tools import ( _ "golang.org/x/tools/cmd/goimports" )
ã½ã¼ã¹ã³ã¼ãå ã§ãã©ã³ã¯ã¤ã³ãã¼ããããããã±ã¼ã¸ã¯ go mod tidy ãã¦ã go.mod ããæ¶ããªããªãã¾ãããã®æ§è³ªã使ã£ã¦ãã¼ã«ã®ããã±ã¼ã¸ãã©ããã§ãã©ã³ã¯ã¤ã³ãã¼ããã¦ããããã¼ã«ã®ãã¼ã¸ã§ã³ãã go.mod ã§ç®¡çãã¡ãããï¼ã¨ããããæ¹ã§ãã
ããã¯å ¬å¼ããæ¡å ããã¦ããã¢ããã¼ãã§ã¯ããã¾ãããããããã¯ãªããæ¹ã«è¦ããªããã¨ãããã¾ãã (å®éãå ¬å¼ãªææ¸ã§ããworkaround ã§ãããã¨ç´¹ä»ããã¦ãããããã¾ã) ã
ã¨ã¯ããæ¬ææ³ã¯ãããªãã«å¤ã (ãã¼ã«ã®å°å
¥ã« go get
ãç¨ãã¦ãã Go 1.16 ãããå) ããæå¹ãªæ段ã§ããããã¤2024å¹´12æç¾å¨ã§ãå¥å¨ãªããæ¹ã§ãã
æ¬ææ³ã§ãã¼ã«ãå°å ¥ããå ´åãæ¦ã以ä¸ã®ãããªæé ãè¸ã¿ã¾ã3ã
- go.mod ãããããã¸ã§ã¯ãã§ã
go install <ãã¼ã«ã®ããã±ã¼ã¸>@latest
ã®ãããªããæ¹ã§ãã¼ã«ãå°å ¥ãã- ãã®æ®µã§ãã¼ã«ã¨ãã¼ã«ã®ä¾åé¢ä¿ã«ããã©ã¤ãã©ãªã®ãã¼ã¸ã§ã³ã go.mod ã«è¨è¼ããã
- tools.go ã«ãã¼ã«ã®ããã±ã¼ã¸ããã©ã³ã¯ã¤ã³ãã¼ããã¦ãã
- ãã®æ®µã§ go mod tidy ãã¦ã ãã¼ã«ã«é¢é£ããä¾åã©ã¤ãã©ãªã go.mod ããæ¶ããªããªã
- 次ãã
go install <ãã¼ã«ã® URL>
ã¨ããã°ãgo.mod ã«è¨è¼ããããã¼ã¸ã§ã³ã®ãã¼ã«ãã¤ã³ã¹ãã¼ã«ããã
Go 1.24 ãããã便å©ãªä»çµã¿ãå ¬å¼ããæä¾ããã
workaround ãããªãã¦ãã£ã¨ä¾¿å©ãªä»çµã¿ãå ¥ããããï¼ã¨ããæã声ããã£ããã©ããã¯åããã¾ããããGo 1.24 ãã tools.go ã«ãããã¼ã«ã®ãã¼ã¸ã§ã³ç®¡çã¨åããããªãã¨ãéæããããã® å°ç¨ã®ä»çµã¿ ãå°å ¥ãããããã§ããé¢é£ issue ã¯ä»¥ä¸ã§ãã github.com
ã¡ãã£ã¨åã¾ã§ Go 1.24 ã«å ¥ããã©ããå¾®å¦ãªæãã ã£ãæ°ããã¾ãããã©ããã Go 1.24 ã«å ¥ã£ã¦ãããããªé°å²æ°ãæ¿åãªããã«è¦ãã¾ãã
以ä¸ã¯ Go 1.24 ã®ãªãªã¼ã¹ãã¼ãã«ãªãäºå®ã®å 容ã§ãããã¡ãã«ããã§ã«é¢é£æ å ±ãè¼ã£ã¦ãã¾ããâ¦ï¼
ãªãªã¼ã¹ãã¼ãã軽ãã¤ã¾ãã§èªãã§ã¿ãã¨ãã©ããã以ä¸ã®ãããªæãã«ãªãããã§ã (æçµçãªå 容ã¯å¤ããå¯è½æ§ãããã¾ã) ã
go get -tool golang.org/x/tools/cmd/stringer
ã®ããã«ãã¦ãã¼ã«ãå°å ¥ãã- ã¤ã³ã¹ãã¼ã«ããããã¼ã«ã®ããã±ã¼ã¸ãæå®ãã¦
go get -tool
ã³ãã³ããå®è¡ããããã§ããã - ãã㨠go.mod å ã® "tool" ã¨ããæ¬ã«ãã¼ã«ã«é¢ããæ å ± (ãªãã¸ã§ã³æ å ±ã¨ä¾åé¢ä¿) ãæ¸ãè¾¼ã¾ãããããã§ãã
- ãã¼ã¸ã§ã³ç®¡çã®æ¹æ³ã¯æ¢åã® go.mod ã¨åããããªæãã«ã§ããã (requireãreplaceãexclude ãªã©ã使ããããã ) ãªãã¨ãæ¸ãã¦ããã¾ãã
- ã¤ã³ã¹ãã¼ã«ããããã¼ã«ã®ããã±ã¼ã¸ãæå®ãã¦
- å°å
¥ãããã¼ã«ãå®è¡ããã«ã¯
go tool stringer
ã®ããã«ãã- å®è¡ããã¨ãã«ã¯ãã¼ã«ã®ããã±ã¼ã¸ã®ãã«ãã¹ãæå®ããå¿ è¦ã¯ãªããæ«å°¾ã®é¨åã ãæå®ããã°è¯ã模æ§
- go.mod ã«æ¸ãè¾¼ã¾ãããã¼ã«ãä¸å¼ã¤ã³ã¹ãã¼ã«ãããã¨ãã¯
go install tool
ã¨ãã- å
¨é¨ã®ãã¼ã«ã
$GOBIN
ã«çªã£è¾¼ã¿ããã¨ãã¯ãããããããã§ãã
- å
¨é¨ã®ãã¼ã«ã
- ãã¼ã«ä¸å¼ã®ãã¼ã¸ã§ã³ãæ´æ°ãããã¨ãã¯
go get -u tool
ã¨ãã- 便å©ããã
ã¾ã¨ã
- Go 1.24 ãããã¼ã«ã®ãã¼ã¸ã§ã³ç®¡çã go.mod ã§è¡ãä»çµã¿ãå°å
¥ãããã
go get -tool <ãã¼ã«ã®ããã±ã¼ã¸>
ã§å°å ¥ããgo tool <ãã¼ã«å>
ã¿ãããªæãã§å®è¡ããããã«ãªãããã
- Go 1.24 ããã¯ãã tools.go ã使ã£ã workaround ãä¸è¦ã«ãªãããã ãâ¦ï¼
Go 1.24 ã®ãªãªã¼ã¹ã¯ 2025å¹´2æãããã§ããé¦ãé·ããã¦å¾ ã£ã¦ããã¾ãããã
- https://docs.renovatebot.com↩
- https://docs.github.com/ja/code-security/dependabot/working-with-dependabot↩
-
ã¡ãªã¿ã«ããã®ããæ¹ã§å
¥ãããã¼ã«ã¨ããã®ããæ¹ãããã«
go install <ãã¼ã«ã® URL>@latest
ã®ããã«ãã¦ãã¼ã«ãå ¥ããå ´åã¨ã§ã¯ãå¾®å¦ã«ç°ãªãçµã¿åããã®ã©ã¤ãã©ãªãç¨ããããå ´åãããã¾ããç¨ã«ãã«ããéããªããªã©ã®åé¡ãå¼ãèµ·ããå ´åãããã¾ãã↩