getters

command module
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2019 License: BSD-3-Clause, MIT Imports: 14 Imported by: 0

README

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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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