Skip to content

calumari/graft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graft

Tiny code generator for type-safe struct mappers in Go (inspired by MapStruct). You write small interfaces; Graft emits plain Go (no reflection) that does the mapping.

Install

go install github.com/calumari/graft@latest

Or use a //go:generate directive (recommended).

Quick Start

// model.go
package demo

//go:generate github.com/calumari/graft/cmd/graftgen -interface=UserMapper -output=mapper_gen.go

type User struct { ID int; Name string }
type UserDTO struct { ID int; Name string }

type UserMapper interface {
    UserToDTO(User) UserDTO
}

Generate & use:

go generate ./...
m := NewUserMapper()
dto := m.UserToDTO(User{ID: 1, Name: "Alice"})

Examples

See the examples/ directory for focused scenarios covering collections, multiple parameters with mapsrc tags, context, custom functions, error propagation, and recursion. Each example contains its own minimal test showing expected behavior.