Idiomatic Go is the community’s customary way of writing Go: established conventions aligned with the language’s design principles. Its purpose is not to justify every convention, but to give projects a consistent tone and make code clear, effective, efficient, maintainable, explicit, pragmatic, and straightforward to test. section 1.1.2
Writing idiomatically requires learning Go’s philosophies and mechanics rather than forcing habits from other languages onto the language. Prefer solving present problems plainly over speculative abstractions, and treat simplicity as a demanding design goal. section 1.1.2 section 1.1
Idiomatic choices include:
- Name packages and their items according to Go conventions. section 2.2
- Handle errors deliberately and decide carefully when struct fields should be exported. section 2.2
- Satisfy standard-library interfaces when practical to integrate with standard-library and third-party functionality. section 2.2.4
- Use tests, table-driven tests, subtests, and example tests to support maintainability and runnable documentation. section 2.0
A URL type that implements Stringer
A URL parser package can define String with a pointer receiver so *URL satisfies fmt.Stringer. Passing a *URL to fmt.Println then calls String automatically; passing a URL value does not, because an interface holding the nonpointer value cannot call its pointer-receiver methods. section 2.2.4
type Stringer interface { #1
String() string #2
}
The Stringer interface shows the small contract a type fulfills to participate in fmt-based formatting. section 2.2.4


