This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net" | |
) | |
func main() { | |
log.SetFlags(log.LstdFlags | log.Lshortfile) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = Describe("Book", func() { | |
var ( | |
longBook Book | |
shortBook Book | |
) | |
BeforeEach(func() { | |
longBook = Book{ | |
Title: "Les Miserables", | |
Author: "Victor Hugo", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package books_test | |
import ( | |
. "/path/to/books" | |
. "github.com/onsi/ginkgo" | |
. "github.com/onsi/gomega" | |
) | |
var _ = Describe("Book", func() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package books_test | |
import ( | |
. "github.com/onsi/ginkgo" | |
. "github.com/onsi/gomega" | |
"testing" | |
) | |
func TestBooks(t *testing.T) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo | |
import "testing" | |
import "fmt" | |
var _ = &testing.T{} | |
func Foo() { | |
fmt.Println("Hello"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 普通单元测试用例 | |
func TestFoo(t *testing.T) { | |
if testing.Short() { | |
t.Skip("skipping test in short mode.") | |
} | |
// ... | |
} | |
// 性能测试用例 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func nakedRecover() { | |
defer recover() // 这样无法捕捉到panic,panic会到达最顶层,导致程序失败退出。 | |
panic("error") | |
} | |
func calleeRecover() { | |
defer func() { | |
// recover使用比较诡异,必须在defer中一个被调用的函数内被调用。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type bar struct { | |
id int | |
name string | |
} | |
func fooEsc(id int, name string) *bar { | |
return &bar { id: id, name: name } // 发生逃逸 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fmt.Println("Go to die!") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Display colored log | |
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit -- | |
# Create a alias for colored log | |
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --" | |
# Use it | |
git lg |
NewerOlder