Introducing goaccessor: A Tool to Generate getter and setter Methods in Go

While working on a project, I often found myself writing repetitive getter and setter methods for Go structs. To streamline this process, I developed goaccessor - a tool that automates this task.

Here’s a quick example of how it integrates:

// With getter
bookIDs := slices.Map(books, (*Book).GetID)  
// Note: slices is an internal generic library we use.

// Without getter
bookIDs := slices.Map(books, func (book *Book) int { return book.ID })  

I’m aware that auto-generating such methods might seem unconventional and might not align perfectly with traditional Go coding styles. However, I wanted to share it here to gather feedback, insights, and potential improvements from the community. : )

Link to the repo

1 Like

Thanks :blush: :people_hugging:

No, just no.

No one should use this!

Go is Not Java!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.