buildergen

command module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 10 Imported by: 0

README

BuilderGen

Go Reference CI Badge

BuilderGen is a tool used for generating builders for Golang structs.

Features

  • Generate builder files from structs
  • Config paths to generate all structs
  • Generate builders with local imports in a different package

QuickStart

Step 1: Install this package
go install github.com/Jh123x/buildergen@latest

Install this package start using it

Step 2: Use the package

This is just 1 out of 2 ways to use this package. For the full list of usage visit docs here. Write the go generate comment as shown in the example below.

package examples

import "github.com/Jh123x/buildergen/examples/nested"

//go:generate buildergen -src=./test.go -name Person

type Person struct {
	ID        int
	Name      string
	Email     *string // Optional field
	PhoneBook []*Contact
	MapVal    map[string]string `json:"map_val"`
	T         nested.Test
}

type Contact struct {
	Name  string
	Phone string
}
Step 3: Using the builder

After running the go generate, you can use the builder similar to what is shown below.

var defaultPerson = &Person{
	ID: 1,
	Name: "John",
	Email: nil,
}

...
func TestXXX(t *testing.T){
	clonedPerson := NewPersonBuilder(defaultPerson).WithID(12).WithName("Johnny").Build() // ID and Name changes
	...
	// Use clonedPerson
}

Documentation

Overview

BuilderGen is a code generation tool to generate builder structs based on your structs.

Directories

Path Synopsis
This is the struct used for examples
This is the struct used for examples
benchmark
This is the code used to benchmark the performance of BuilderGen
This is the code used to benchmark the performance of BuilderGen
nested
A nested struct in a different package
A nested struct in a different package
internal
cmd
Code generated by BuilderGen v0.2.0
Code generated by BuilderGen v0.2.0
parser/data
Code generated by BuilderGen v0.0.7
Code generated by BuilderGen v0.0.7

Jump to

Keyboard shortcuts

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