Design APIs with minimal exposed surface by encapsulating implementation details within packages. When designing APIs, expose only what's necessary for consumers while keeping internal details hidden.
Design APIs with minimal exposed surface by encapsulating implementation details within packages. When designing APIs, expose only what’s necessary for consumers while keeping internal details hidden.
For example, instead of exposing complex types that clients must construct:
// Avoid exporting internal types
type DeprecatedOutputDiagnosticExtra struct {
Cause DeprecationCause
wrapped interface{}
}
// Instead, provide wrapper functions that hide implementation details
func DeprecatedOutputDiagnosticOverride(cause DeprecationCause) func() tfdiags.DiagnosticExtraWrapper {
return func() tfdiags.DiagnosticExtraWrapper {
return &DeprecatedOutputDiagnosticExtra{
Cause: cause,
}
}
}
When making changes to existing APIs:
This approach prevents external code from depending on implementation specifics, makes the codebase more maintainable, and enables future refactoring without breaking compatibility.
Enter the URL of a public GitHub repository