funcinit(){ fmt.Printf("\nchorder.net/example/src2.go init() has been called.") }
funcSrc2(){ fmt.Printf("\nchorder.net/example/src2.go Src1() has been called.") }
编写代码调用这两个包中的方法:
packge_test.go
1 2 3 4 5 6 7 8
package main
import"chorder.net/example"
funcmain(){ example.Src1() example.Src2() }
执行结果:
1 2 3 4 5 6
>go run packge_test.go
chorder.net/example/src1.go init() has been called. chorder.net/example/src2.go init() has been called. chorder.net/example/src1.go Src1() has been called. chorder.net/example/src2.go Src1() has been called.