Add helloweb snippet (#1113)
`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.
This commit is contained in:
Родитель
a91df3d790
Коммит
4f33a078a8
|
@ -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": {
|
||||
|
@ -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}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче