1. Background
- Implementing the Reader exercise while learning the Go Tour
- The code logic is correct, and the command line successfully outputs “OK!”
- However, the VSCode IDE continuously displays an import error
2. First pitfall: Dependency download failure (502 Bad Gateway). For reference: Complete Record of Pitfalls Encountered When Running the Go Tour Slice Exercise Locally (From Error to Successful Execution) See Figure 1

Error message:
Plaintext
go: downloading golang.org/x/tour v0.1.0
go: reading https://goproxy.io/golang.org/x/tour/@v/v0.1.0.zip: 502 Bad GatewayCause of the error:
- The default Go module proxy
goproxy.iois temporarily unavailable
Solution:
Plaintext
# Unset GOPROXY to let Go access the official source directly, then rerun
/app/go-tour/exercise-reader # unset GOPROXY
/app/go-tour/exercise-reader # go get golang.org/x/tour/reader
go: downloading golang.org/x/tour v0.1.0
/app/go-tour/exercise-reader # go run main.go
OK!3. Second pitfall: The IDE still displays an import error. See Figure 2

Symptom:
- Executing
go run main.goin the terminal outputs “OK!” ✅ - The VSCode editor shows a red squiggly line:
could not import golang.org/x/tour/reader❌
Cause analysis:
- The IDE’s language server (gopls) has cached the old module state
- The module dependency has been downloaded, but the IDE has not synced the latest information
Solution: See Figure 3

Plaintext
# Method: Reload VSCode window (recommended)
# Ctrl+Shift+P → Type "Reload Window"4. Complete code example, the IDE no longer displays an import error. See Figure 4

Go
package main
import "golang.org/x/tour/reader"
type MyReader struct{}
func (r MyReader) Read(b []byte) (int, error) {
for i := range b {
b[i] = 'A'
}
return len(b), nil
}
func main() {
reader.Validate(MyReader{})
}5. Summary of experience
- Network issues: Accessing golang.org from within China may require adjusting proxy settings
- IDE cache: After the command line succeeds, remember to refresh the IDE’s language server
- Troubleshooting order: First ensure
go runcan succeed, then address the IDE error
