Skip to content

refactor: make API Service fields private to prevent abstraction bypass #45

@rianjs

Description

@rianjs

Summary

Client.Service is exported, allowing callers to bypass the abstraction.

Current State

Files:

  • internal/gmail/client.go:29 - Service *gmail.Service
  • internal/calendar/client.go:26 - Service *calendar.Service
  • internal/contacts/client.go:23 - Service *people.Service
type Client struct {
    Service *gmail.Service  // Exported!
    // ...
}

Problems

  1. External code can bypass the Client abstraction
  2. Makes it impossible to track API usage
  3. Prevents adding cross-cutting concerns (logging, metrics)
  4. Defeats the purpose of the abstraction

Proposed Solution

Make service lowercase and expose functionality through methods only:

type Client struct {
    service *gmail.Service  // Private!
    // ...
}

func (c *Client) GetMessage(id string) (*Message, error) {
    // Use c.service internally
}

Priority

P2 - Design improvement (depends on interface work in #35)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions