タグ

goとERRORに関するMukeのブックマーク (2)

  • Mocking dependencies in Go

    OverviewWe all use a lot of packages when constructing our applications, both internally developed and third party packages. This blog post will show how you can easily mock these packages using mockery and stretchr/testify/mock. Let’s dive into it; An exampleWhen writing unit tests for our code we might find the external packages problematic. Consider this case: import "github.com/mediocregopher/

  • Golangを触り始めた② 文法・型 - blue_field

    前回に引き続き、Web+DB vol.82のGo特集が分かりやすいのでそれ見ながら。 ぜんぶ網羅して書いてないけど、メモ。Goのバージョンは1.3.3です。 変数 var message string = "Hello world" 変数宣言は、varで始まり、変数名、型の順。ちょっと違和感。 関数内部で変数宣言と初期化を行う場合は、以下のように:=を利用しても書ける。こっちの書き方を使うことが多そう。変数の型は、代入する値から推論される。 /* import文は省略 */ func main() { message := "Hello world" fmt.Println(message) } 定数は、varじゃなくてconstで宣言。 if 条件部分に()は付けないが、処理部分は{}が必要。 func main() { a, b := 10, 1 if a > b { fmt.Prin

    Golangを触り始めた② 文法・型 - blue_field
  • 1