gcraft

module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2026 License: MIT

README ΒΆ

gcraft

Go Version Go Report Card GoDoc

gcraft is a Go code generation tool that reads your struct and interface definitions and automatically generates idiomatic boilerplate β€” Builder pattern, Mocks, Validators, and Clone methods β€” so you can focus on business logic instead of repetitive code.

Why gcraft?

Writing the same boilerplate for every struct is tedious and error-prone. gcraft analyzes your code using Go's AST and generates clean, production-ready code right next to your source files.

# Before: write 80 lines of boilerplate by hand
# After:
gcraft generate ./...

Features

  • πŸ—οΈ Builder pattern β€” fluent builder for any struct
  • πŸ§ͺ Mock generation β€” interface mocks for testing
  • βœ… Validator β€” struct validation boilerplate
  • πŸ” Clone β€” deep copy methods
  • βš™οΈ go generate compatible
  • πŸ“¦ Zero dependencies (uses only Go stdlib)

Installation

go install github.com/Mahdyaralipor/gcraft/cmd/gcraft@latest

Quick Start

Given this struct:

// user.go
//go:generate gcraft generate -type User

type User struct {
    ID    int
    Name  string
    Email string
    Age   int
}

Run:

gcraft generate -type User -src ./user.go

gcraft generates user_gen.go:

// UserBuilder β€” fluent builder
user := NewUserBuilder().
    WithID(1).
    WithName("Alice").
    WithEmail("alice@example.com").
    Build()

// Validate
if err := user.Validate(); err != nil {
    log.Fatal(err)
}

// Clone
copy := user.Clone()

Usage

gcraft generate [flags]

Flags:
  -type     Type name to generate for (required)
  -src      Source file or directory (default: current directory)
  -out      Output file (default: <type>_gen.go)
  -builder  Generate Builder pattern (default: true)
  -mock     Generate Mock for interfaces (default: true)
  -validate Generate Validator (default: true)
  -clone    Generate Clone method (default: true)

Examples

See the examples/ directory for complete working examples.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md first.

License

MIT β€” see LICENSE

Directories ΒΆ

Path Synopsis
cmd
gcraft command
gcraft β€” Go boilerplate code generator
gcraft β€” Go boilerplate code generator
examples
internal
generator
Package generator produces Go source code from parsed type information.
Package generator produces Go source code from parsed type information.
parser
Package parser parses Go source files and extracts type information using Go's standard AST (Abstract Syntax Tree) libraries.
Package parser parses Go source files and extracts type information using Go's standard AST (Abstract Syntax Tree) libraries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL