Skip to content
/ getters Public

Code generator tool that generates getter methods for structs with pointer fields

License

Notifications You must be signed in to change notification settings

tors/getters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getters

Getters is a code generator tool for Go. It generates getter methods for structs with pointer fields.

Getters is a standalone version of gen-accessors from google/go-github. Aside from it's standalone, it's customizable too and has more primitive types support such as floats and uints.

type Pony struct {
	Name   *string
	Age    *int64
}

Generates...

func (p *Pony) GetAge() int64 {
	if p == nil || p.Age == nil {
		return 0
	}
	return *p.Age
}

func (p *Pony) GetName() string {
	if p == nil || p.Name == nil {
		return ""
	}
	return *p.Name
}

Install

go get -u github.com/tors/getters

Usage

Command line

# Basic usage
# Looks for .getters.yml. If it doesn't exist, this will generate
# getter methods for all struct pointer fields.
getters

# Checks custom_getters.yml with verbose mode on
getters -v custom_getters.yml

# Merge and override options
getters -v -s Pony,Kitten -m Horse.GetName,Cat.GetAge

# Ignore main package
getters -p main

Generators

//go:generate getters
//go:generate getters -v -s Pony,Kitten -m Horse.GetName,Cat.GetAge

Here's an example of a config file

About

Code generator tool that generates getter methods for structs with pointer fields

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages