Skip to content

Align code to accept interfaces and return concrete structs #74

@gabor-boros

Description

@gabor-boros

Description

Align the codebase with the Go best practice: "Accept interfaces, return structs" to improve flexibility and API clarity.

Some parts of the code do not follow the common Go convention:

  • Functions and methods should accept interfaces as parameters, enabling flexibility.
  • They should return concrete structs, which provide clarity and avoid unnecessary abstractions.

Following this pattern makes the code more idiomatic and easier for Go developers to understand and maintain.

Tasks

  1. Review the codebase to find functions or methods that:
    • Accept concrete structs instead of interfaces.
    • Return interfaces instead of structs.
  2. Refactor these to:
    • Accept interfaces where appropriate.
    • Return structs instead of interfaces where it improves clarity or safety.
  3. Consider API protection:
    • Returning interfaces can sometimes hide implementation details but may reduce clarity.
    • Choose the best approach case-by-case.
  4. Test all affected code to ensure no behavior changes or breakages.

Notes

  • Use this as a guideline, not a strict rule, apply changes only where it makes sense.
  • This improves code readability, testability, and adherence to Go idioms.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions