Skip to content

Commit

Permalink
Add helloweb snippet (golang#1113)
Browse files Browse the repository at this point in the history
`helloweb` generates small web app with an http endpoint
which returns a greeting and the current time.

This is can be used to quickly generate a minimal web app
for demo purposes.
  • Loading branch information
thomasdarimont authored and ramya-rao-a committed Jul 27, 2017
1 parent a91df3d commit 4f33a07
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion snippets/go.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"body": "func Benchmark$1(b *testing.B) {\n\tfor ${2:i} := 0; ${2:i} < b.N; ${2:i}++ {\n\t\t$0\n\t}\n}"
},
"table driven test": {
"prefix": "tdt",
"prefix": "tdt",
"body": "func Test$1(t *testing.T) {\n\ttestCases := []struct {\n\t\tdesc\tstring\n\t\t$2\n\t}{\n\t\t{\n\t\t\tdesc: \"$3\",\n\t\t\t$4\n\t\t},\n\t}\n\tfor _, tC := range testCases {\n\t\tt.Run(tC.desc, func(t *testing.T) {\n\t\t\t$0\n\t\t})\n\t}\n}"
},
"init function": {
Expand All @@ -175,6 +175,10 @@
"method declaration": {
"prefix": "meth",
"body": "func (${1:receiver} ${2:type}) ${3:method}($4) $5 {\n\t$0\n}"
},
"hello world web app": {
"prefix": "helloweb",
"body": "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"time\"\n)\n\nfunc greet(w http.ResponseWriter, r *http.Request) {\n\tfmt.Fprintf(w, \"Hello World! %s\", time.Now())\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", greet)\n\thttp.ListenAndServe(\":8080\", nil)\n}"
}
}
}

0 comments on commit 4f33a07

Please sign in to comment.