From 23716b7b708853a51b585e0a2f8c7bbc5e09d2a9 Mon Sep 17 00:00:00 2001 From: Hiroaki Sano Date: Mon, 27 Jan 2020 23:06:44 +0900 Subject: Add table driven testing for go --- template/go/snip-test-table-driven.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 template/go/snip-test-table-driven.go (limited to 'template') diff --git a/template/go/snip-test-table-driven.go b/template/go/snip-test-table-driven.go new file mode 100644 index 0000000..f98786d --- /dev/null +++ b/template/go/snip-test-table-driven.go @@ -0,0 +1,19 @@ +func Test{{_cursor_}}(t *testing.T) { + tests := []struct{ + name string + want int + }{ + { + name: "case1", + want: 1, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T){ + got := 1 + if got != tt.want { + t.Fatalf("want %v, but %v:", tt.want, got) + } + }) + } +} -- cgit v1.2.3-54-g00ecf From 0a50049b8b828c3235f80ecc2c95b936376cf763 Mon Sep 17 00:00:00 2001 From: Hiroaki Sano Date: Mon, 27 Jan 2020 23:10:38 +0900 Subject: Add err handling --- template/go/snip-err-log-fatal.go | 3 +++ template/go/snip-err-return.go | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 template/go/snip-err-log-fatal.go create mode 100644 template/go/snip-err-return.go (limited to 'template') diff --git a/template/go/snip-err-log-fatal.go b/template/go/snip-err-log-fatal.go new file mode 100644 index 0000000..48a2c6b --- /dev/null +++ b/template/go/snip-err-log-fatal.go @@ -0,0 +1,3 @@ +if err != nil { + log.Fatal(err) +} diff --git a/template/go/snip-err-return.go b/template/go/snip-err-return.go new file mode 100644 index 0000000..4936685 --- /dev/null +++ b/template/go/snip-err-return.go @@ -0,0 +1,3 @@ +if err != nil { + return err +} -- cgit v1.2.3-54-g00ecf From 7fc55ca2e5d11ffe399751519ae4dd24bf1fdb9e Mon Sep 17 00:00:00 2001 From: Hiroaki Sano Date: Mon, 27 Jan 2020 23:20:23 +0900 Subject: Add time format for go --- template/go/snip-time-date.go | 1 + template/go/snip-time-format-yyyymmddHHMMss-micro.go | 1 + template/go/snip-time-format-yyyymmddHHMMss-milli.go | 1 + template/go/snip-time-format-yyyymmddHHMMss-nano.go | 1 + 4 files changed, 4 insertions(+) create mode 100644 template/go/snip-time-date.go create mode 100644 template/go/snip-time-format-yyyymmddHHMMss-micro.go create mode 100644 template/go/snip-time-format-yyyymmddHHMMss-milli.go create mode 100644 template/go/snip-time-format-yyyymmddHHMMss-nano.go (limited to 'template') diff --git a/template/go/snip-time-date.go b/template/go/snip-time-date.go new file mode 100644 index 0000000..664ebf4 --- /dev/null +++ b/template/go/snip-time-date.go @@ -0,0 +1 @@ +tm := time.Date(2006, time.January, 2, 15, 4, 5, 0, time.Local) diff --git a/template/go/snip-time-format-yyyymmddHHMMss-micro.go b/template/go/snip-time-format-yyyymmddHHMMss-micro.go new file mode 100644 index 0000000..833f945 --- /dev/null +++ b/template/go/snip-time-format-yyyymmddHHMMss-micro.go @@ -0,0 +1 @@ +"2006/01/02 15:04:05.000000" diff --git a/template/go/snip-time-format-yyyymmddHHMMss-milli.go b/template/go/snip-time-format-yyyymmddHHMMss-milli.go new file mode 100644 index 0000000..b4fba80 --- /dev/null +++ b/template/go/snip-time-format-yyyymmddHHMMss-milli.go @@ -0,0 +1 @@ +"2006/01/02 15:04:05.000" diff --git a/template/go/snip-time-format-yyyymmddHHMMss-nano.go b/template/go/snip-time-format-yyyymmddHHMMss-nano.go new file mode 100644 index 0000000..cb9c57b --- /dev/null +++ b/template/go/snip-time-format-yyyymmddHHMMss-nano.go @@ -0,0 +1 @@ +"2006/01/02 15:04:05.000000000" -- cgit v1.2.3-54-g00ecf