in

Accessor methods generator for Go programming language


accessory is an accessor generator for Go programming language.

convention,
setter’s name is Set<FieldName>() and getter’s name is <FieldName>() by default,
in other words, Set will be put into setter’s name and Get will not be put into getter’s name.

You can customize names for setter and getter if you want.

type MyStruct struct {
    field1 string `accessor:"getter:GetFirstField"`
    field2 int    `accessor:"setter:ChangeSecondField"`
}

Generated methods will be

func(m *MyStruct) GetFirstField() string {
    return m.field1
}

func(m *MyStruct) ChangeSecondField(val *int) {
    m.field2 = val
}

Accessor methods won’t be generated if accessor tag isn’t specified.
But you can explicitly skip generation by using - for tag value.

type MyStruct struct {
    ignoredField `accessor:"-"`
}

MIT License.

GitHub

View Github




Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

GIPHY App Key not set. Please check settings

DataDog vs Grafana – Key features & differences

Samsung Galaxy S21 FE Launch Date Likely Pegged for October 2021