Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go Modules: From Basics to Beyond / Go Modulesの...

Avatar for kuro kuro
June 07, 2025

Go Modules: From Basics to Beyond / Go Modulesの基本とその先へ

COEFL Go-JP #1で使ったスライドです。

参考リンク
- Go Wiki: Modules(https://go.dev/wiki/Modules)
- Go Module Reference(https://go.dev/ref/mod)

Avatar for kuro

kuro

June 07, 2025
Tweet

More Decks by kuro

Other Decks in Programming

Transcript

  1. // v0, v1: No suffix required import "github.com/user/pkg" // v2+:

    Major version in path goimport "github.com/user/pkg/v2"
  2. my-repo/ ├── go.mod # Root module ├── foo/ │ └──

    go.mod # Sub-module └── bar/ └── go.mod # Another sub-module
  3. # Create go.work file go work init . ./foo ./bar

    go work use ./additional-module test-all: cd . && go test ./... cd foo && go test ./... cd bar && go test ./...
  4. project/ ├── go.mod ├── docs/ │ └── go.mod # Empty

    go.mod = exclude this directory ├── examples/ │ └── go.mod # Empty go.mod = exclude this too └── testdata/
  5. // go.mod module example.com/mymodule retract v1.0.1 // Critical security vulnerability

    retract [v1.2.0, v1.2.5] // Range retraction $ go list -m -versions example.com/mymodule example.com/mymodule v1.0.0 v1.0.2 v1.1.0 # v1.0.1 is skipped
  6. my-repo/ ├── go.mod # ɏüȬɆȜɉüɏ ├── foo/ │ └── go.mod

    # șȺɆȜɉüɏ └── bar/ └── go.mod # ತǟșȺɆȜɉüɏ
  7. # go.work go work init . ./foo ./bar go work

    use ./additional-module test-all: cd . && go test ./... cd foo && go test ./... cd bar && go test ./...
  8. project/ ├── go.mod ├── docs/ │ └── go.mod # յǟgo.mod

    = DŽǟȫȇɐȓȬɎȃࠎЖ ├── examples/ │ └── go.mod # յǟgo.mod = DŽǽdzࠎЖ └── testdata/
  9. // go.mod module example.com/mymodule retract v1.0.1 // retract [v1.2.0, v1.2.5]

    // $ go list -m -versions example.com/mymodule example.com/mymodule v1.0.0 v1.0.2 v1.1.0 # v1.0.1 ッ