template.go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
package doc
import "fmt"
const ConstOne = "const one"
const ConstTwo = "const two"
const ( ConstThree = "const three" ConstFour = "const four" )
var VarOne = "var one"
var VarTwo = "var two"
var ( VarThree = "var three" VarFour = "var four" )
type Namer interface { GetName() string }
func FunctionOne() { fmt.Println("function one") }
func FunctionTwo() { fmt.Println("function two") }
type StructOne struct{}
func NewStructOne() *StructOne { return &StructOne{} }
func (StructOne) GetName() string { return "StructOne" }
type StructTwo struct{}
|
example_test.go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package doc
import "fmt"
func Example_one() { fmt.Println("example one")
}
func Example_two() { fmt.Println("example two")
}
func ExampleNamer() { fmt.Println("namer") }
func ExampleStructOne() { fmt.Println("const one") }
func ExampleNewStructOne() { fmt.Println("new struct one") }
func ExampleStructOne_GetName() { fmt.Println("get name") }
|
参考
https://elliotchance.medium.com/godoc-tips-tricks-cda6571549b