- Formatting should be performed by
gofmt
.
-
Packages should have a top block comment for documentation - multi file packages should only have one comment.
-
Comments are plain text, no annotations for formatting is needed.
-
Comments preceding top-level declarations are used for documentation. Every exported name should have a doc comment.
// Foo is an example of how doc comments should be. func Foo() { return "foo" }
-
Related constants or variables may have only one comment to introduce them.
// Dimentions of something. var( length uint32 width uint32 )
Names have a semantic effect in Go. So naming is very important.
- Go uses cammelCase and PascalCase to multiword names.
- Names preceded with upper case are exported.
- Package names should refer to it's content. They should be short, concise and evocative. Package names MUST:
- Have one word.
- Be lower case.
- NOT have mixedCase or under_scores.
- Getters and setters may be used when necessary.
- Getters should not take the prefix
get
. If there's a fieldname
it's getter must be calledName
. - Setters should take the prefix
set
. If there's a fieldname
it's setter must be calledSetName
.
- One-method interfaces should be named with the method's name followed by the suffix
er
. E.g.Reader
,Writer
. - Well-known method's names such as
Read
,Write
,Flush
,Close
, should only be used if they have the same signature and meaning. E.g. a string converter should be calledString
notToString
.
- Array pointers like
array *[10]float64
are not idiomatic and should be avoided. Slices should be used instead.
- golang/go
- Effective Go
- Writing Web Applications
- Introduction
- Learn Web Programming in Go by Examples
- Go by Example
- golang/go
- Learn Go reflections and generic designs with a practical example
- Less is exponentially more
- SOLID Go Design
- Self-referential functions and the design of options
- Functional options for friendly APIs
- Advanced Go Concurrency
- How I Built Microservices In Go In 30 Minutes
- Why Go Is Successful (aka Simplicity is Complicated)
- Concurrency Patterns In Go
- Writing Beautiful Packages in Go
- Simulating A Real-World System (Coffee Shop) In Go
- Self Deploying Go Applications
- How Do You Structure Your Go Apps?
- Advanced Topics in Programming Languages: Concurrency/message passing Newsqueak
- Go In 5 Minutes - Short, helpful screencasts for professional Go developers