go语句不用加分号,和python一样。
go的运行方式:go run xx.go
test的运行方式:go test testXXX.go -v
增加新的包:go get xxx
第一个go程序
package mainimport "fmt"func main() { fmt.Println("Hello, world!")}- 函数的定义
func function_name([parameter list]) [return_types] {// body}- 第一个test函数
引入包”testing”,函数必需命名为TestXXX,参数必需包含一个Testing类型的指针。下面是一个简单的例子,TestF1测试f1。
package testimport "testing"func f1(a int,b int) int{ return a+b}func TestF1(t *testing.T){ if f1(1,2) != 3{ t.Error(`f1 error!`) }}测试结果
=== RUN TestF1--- PASS: TestF1 (0.00s)PASSProcess finished with exit code 0