There is no problem not worth solving, and no technology not worth learning!

Go reports an error in VS Code: Main redeclared in this block

在 VS Code 中 Go 报错: main redeclared in this block。原因在于目录里有多个 main 函数。

1. In VS Code, Go reports an error: Main redeclared in this block. The reason is that there are multiple main functions in the directory. as shown in Figure 1

Go reports an error in VS Code: Main redeclared in this block. The reason is that there are multiple main functions in the directory.

2. Reorganize an exercise directory structure scheme of A Tour of Go to ensure that each exercise can run go run main.go independently, and there will be no Main Rededeclared error. I decided to use the filename as the directory name, and then the filename is unified as main

go-gin-learning/
├── .devcontainer/
│ └── devcontainer.json
├── .gitignore
├── readme.md
├── docker-compose.yml
├── go.mod
├── go.sum
├── main.go # Original GIN project entrance
└─ GO-TOUR/ # GO TOUR Exercise Catalog
├── hello/
│ └── main.go
├──imports/
│ └── main.go
└── packages/
└── main.go

3. No more errors: main redeclared in this block.

Need long-term technical maintenance or remote troubleshooting?

I am a PHP / Go backend engineer with 15+ years of experience, focused on existing system maintenance, bug fixing, performance optimization, server troubleshooting, WordPress maintenance, and small feature iterations.

If your project is facing any of the following issues, we can start with a small troubleshooting task first:

  • ✅ PHP / Laravel / Yii2 legacy systems without active maintenance
  • ✅ Go / Gin backend APIs that need troubleshooting or optimization
  • ✅ Slow, broken, or unstable WordPress websites
  • ✅ Nginx / MySQL / Redis / Linux server issues
  • ✅ CDN / Cloudflare / DNS / HTTPS configuration problems
  • ✅ Long-term remote technical support or part-time maintenance

More details: About Me & Collaboration

WeChat: 13980074657
Email: shuijingwanwq@gmail.com
Telegram: @shuijingwan
GitHub: https://github.com/shuijingwan

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.