Skip to content

Repository files navigation

gen-dto

gen-dto logo

Generate bidirectional DTO converters for Go structs.

CI License: MIT Go Version

gen-dto is a CLI tool that generates conversion code between Go structs using go:generate.

Highlights

  • Generates both directions in one file (A -> B and B -> 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

Installation

go install

go install github.com/seitarof/gen-dto/cmd/gen-dto@latest

Homebrew

brew tap seitarof/homebrew-tap
brew install gen-dto

Quick Start

//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,SecretKey
go generate ./...

CLI

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

Supported Go Version

  • Go 1.26.x

Documentation

License

MIT License. See LICENSE.

About

gen-dto is a Go CLI that generates DTO conversion code between structs via go:generate.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages