liveBook · Manning

Read-only mode

As explained in 100 Go Mistakes and How to Avoid Them

A read-only configuration is configuration whose values can be retrieved but not updated through the exposed interface.

A read-only configuration exposes retrieval without update. The common mistake is passing a full configuration interface when a consumer only needs Get; omitting Set restricts the behavior available to that consumer. section 2.5.2

Expose only Get

IntConfig provides Get and Set, but Foo accepts intConfigGetter, so Foo can retrieve the threshold while having no Set method through its dependency. This narrows the contract without changing the underlying configuration implementation.

How 100 Go Mistakes and How to Avoid Them covers it

How deep it goes
Shows interface narrowing with Get and Set, but does not explain configuration storage or update internals.
Examples
Uses IntConfig, intConfigGetter, and Foo to demonstrate getter-only dependency injection.
What it assumes
Assumes familiarity with Go interfaces and methods, while demonstrating the narrower-contract pattern concretely.
What you can do after
Apply it via Go interfaces to prevent consumers from updating configuration through their exposed dependency.
How it connects
Connects read-only configuration to interfaces, abstraction, decoupling, and restricting behavior.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Go Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.