Manage Go modules and dependency versioning
✓Works with OpenClaudeYou are a Go module management expert. The user wants to manage Go modules and dependency versioning effectively.
What to check first
- Run
go versionto confirm Go 1.11+ is installed (modules require this) - Check if a
go.modfile exists in your project root withls -la go.mod
Steps
- Initialize a new module with
go mod init github.com/username/projectnamein your project root - Add dependencies by importing them in your code, then run
go mod tidyto download and record them ingo.mod - View your dependency tree with
go mod graphorgo list -m allto see all direct and transitive dependencies - Pin a specific version by editing
go.moddirectly or runninggo get package@v1.2.3(replace with actual version) - Update all indirect dependencies to their latest patch versions with
go get -u=patch ./... - Update all dependencies including minor and major versions with
go get -u ./...(use cautiously for major versions) - Remove unused dependencies and clean up
go.modandgo.sumby runninggo mod tidy - Verify your dependencies haven't been tampered with using
go mod verify
Code
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
func main() {
// Initialize a module if go.mod doesn't exist
if _, err := os.Stat("go.mod"); os.IsNotExist(err) {
moduleName := "github.com/example/myapp"
cmd := exec.Command("go", "mod", "init", moduleName)
if err := cmd.Run(); err != nil {
fmt.Printf("Failed to initialize module: %v\n", err)
os.Exit(1)
}
fmt.Printf("Initialized module: %s\n", moduleName)
}
// Add a dependency: go get github.com/sirupsen/logrus@v1.9.3
cmd := exec.Command("go", "get", "github.com/sirupsen/logrus@v1.9.3")
if err := cmd.Run(); err != nil {
fmt.Printf("Failed to add dependency: %v\n", err)
os.Exit(1)
}
// Tidy up go.mod and go.sum
cmd = exec.Command("go", "mod", "tidy")
if err := cmd.Run(); err != nil {
fmt.Printf("Failed to tidy modules: %v\n", err)
os.Exit(1)
}
fmt.Println("Dependencies tidied")
// List all dependencies with versions
cmd = exec.Command("go", "list", "-m", "all")
output, err := cmd.Output()
if err != nil {
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Go Skills
Other Claude Code skills in the same category — free to download.
Go API Setup
Scaffold Go REST API with Gin or Chi router
Go Testing
Set up Go testing with table-driven tests and mocks
Go Concurrency
Implement goroutines, channels, and concurrency patterns
Go Docker
Create optimized multi-stage Docker build for Go apps
Go gRPC
Set up gRPC server and client in Go
Go Middleware
Create HTTP middleware chain in Go
Go CLI
Build CLI applications with Cobra in Go
Want a Go skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.