Supposing the following example:
package main
import "fmt"
type IReport interface {
DisplayName()
}
type Person struct {
Name string
}
func (p *Person) DisplayName() {
if p == nil {
fmt.Println("<no name provided>\n")
return
}
fmt.Println(p.Name)
}
func main() {
var p *Person = nil
var i IReport = p
describe(i)
i.DisplayName()
i = &Person{"Julia"}
describe(i)
i.DisplayName()
}
func describe(i IReport) {
fmt.Printf("(%+v, %T)\n", i, i)
}
What are the best practice for organizing these methods?
Should we code in this order?
-
- declare interfaces
-
- declare types
-
- declare interface methods
-
- declare main method
-
- declare private / public functions
Also if should we avoid adding the type name to types (Report instead of IReport or ReportInterface…)?
How to make types and interfaces reusable, can we put interfaces and types in a external packages for reusing them different go files by import
ing?
Any other recommendations for organizing code (folders structure, file naming, package naming…)?