Generate bidirectional DTO converters for Go structs.
gen-dto is a CLI tool that generates conversion code between Go structs using go:generate.
- Generates both directions in one file (
A -> BandB -> A) - Case-insensitive field matching
- Supports type aliases (
type X = otherpkg.Y) - Recursively handles nested structs (including same-module cross-package types)
- Leaves unsupported fields as TODO comments without blocking other conversions
go install github.com/seitarof/gen-dto/cmd/gen-dto@latestbrew tap seitarof/homebrew-tap
brew install gen-dto//go:generate gen-dto \
// --src-type=User \
// --src-path=./internal/domain/model \
// --dst-type=UserResponse \
// --dst-path=./internal/dto \
// --filename=user_conv_gen.go \
// --ignore-fields=Password,SecretKeygo generate ./...Required flags:
--src-type,-s--src-path--dst-type,-d--dst-path--filename,-o
Optional flags:
--ignore-fields--func-name(forward root conversion name)--version,-v
- Go
1.26.x
- Contributor guide: CONTRIBUTING.md
MIT License. See LICENSE.