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. : )