# Go: ./main.go:12:2: undefined: handler

**Code:** `undefined: x` · **Category:** Go · **Seen on:** Go

The compiler cannot find an identifier — a typo, a missing import, or it lives in another file/package that wasn't built.

## Meaning

Check spelling and case (exported names start with an uppercase letter). With `go run main.go` only that file is compiled; use `go run .` so other files in the package are included. Verify the import path for package-qualified names.

## Common causes

- Typo or wrong capitalisation
- Function defined in another file but running `go run main.go`
- Missing import for the package
- Variable declared in an inner scope
- Build tags excluding the file

## Quick fix

1. Run `go run .` or `go build ./...` instead of one file
2. Add the missing import
3. Fix the name's capitalisation

## Detailed fix by platform

### Go

1. `go vet ./...` and `go build ./...` show all undefined names in the module

## How to diagnose

1. **Command** — One file or package?
2. **Name** — Case and spelling?
3. **Import** — Present?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/undefined-name)
