文件名须以”_test.go”结尾

方法名须以”Test”打头,并且形参为 (t *testing.T)

举例:/hello_test.go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

package main

import (
"testing"
"fmt"
)

func TestHello(t *testing.T) {
fmt.Println("TestHello")
}

func TestWorld(t *testing.T) {
fmt.Println("TestWorld")

阅读更多

Mac 下编译 Linux 和 Windows 64位可执行程序

1
2
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

Linux 下编译 Mac 和 Windows 64位可执行程序

1
2
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

Windows 下编译 Mac 和 Linux 64位可执行程序

1
2
3
4
5
6
7
8
9
SET CGO_ENABLED=0
SET GOOS=darwin
SET GOARCH=amd64
go build main.go

SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build main.go

摘要

defer 意为延迟,在 golang 中用于延迟执行一个函数。它可以帮助我们处理容易忽略的问题,如资源释放、连接关闭等。但在实际使用过程中,有一些需要注意的地方(坑),下面我们一一道来。

匿名与有名返回值

匿名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main

import (
"fmt"
)

func main() {
fmt.Println("a return:", a()) // 打印结果为 a return: 0
}

func a() int {
var i int
defer func() {
i++
fmt.Println("a defer2:", i) // 打印结果为 a defer2: 2
}()
defer func() {
i++
fmt.Println("a defer1:", i) // 打印结果为 a defer1: 1
}()
return i
}

阅读更多

Problem

1
2
3
4
5
6
7
8
Error report:
ORA-00604: error occurred at recursive SQL level 1
ORA-01653: unable to extend table SYS.IDL_UB2$ by 128 in tablespace SYSTEM
00604. 00000 - "error occurred at recursive SQL level %s"
*Cause: An error occurred while processing a recursive SQL statement
(a statement applying to internal dictionary tables).
*Action: If the situation described in the next error on the stack
can be corrected, do so; otherwise contact Oracle Support.

阅读更多

前言

最近在调研Drill,需要导入大量的测试数据来评估下其查询性能是否满足需要,于是就看到了TPC-DS,折腾了一番,毕竟没有详细的文档,总览一部分查询后,简单整理如下(仅限于导入到MySQL):

阅读更多