reflect
Advancedimport "reflect"Implements run-time reflection allowing inspection and manipulation of types and values.
Example
package main
import (
"fmt"
"reflect"
)
func main() {
x := 42
t := reflect.TypeOf(x)
v := reflect.ValueOf(x)
fmt.Println(t, v, t.Kind())
}Key Types & Functions
TypeOfValueOfTypeValueKindStructFieldAbout reflect
The reflect package (imported as reflect) belongs to the Advanced category of Go packages. Implements run-time reflection allowing inspection and manipulation of types and values.
Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The reflect package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.
When using reflect in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.