私の 2 つのファイル main.go と index.html を見てください。私は Goji Web マイクロフレームワークから始めています。Goji Web フレームワークでスニペットを検索します。
私の例では、@Localhost8000 で HTML フォーム webpage index.html を確認でき、入力フィールドに「test」などと入力して送信ボタンを押すことができます。端末出力では、「Started GET "/?name=test" from 127.0.0.1:51580」が送信されたことがわかります。
変数でgolangへのHTML GETフォームリクエストを取得するにはどうすればよいですか? goji.Get でいくと思います。いくつかの方法を試しましたが、実行できませんでした。どなたかヒントやスニペットを教えていただけると幸いです。私はまだgolangを学んでいます。
ファイル main.go:
package main
import (
"net/http"
"github.com/zenazn/goji"
)
func main() {
staticFilesLocation := "public"
goji.Handle("/", http.FileServer(http.Dir(staticFilesLocation)))
goji.Serve()
}
ファイル index.html:
<html>
<head>
</head>
<body>
<!-- Simple form which will send a GET request -->
<form action="">
<label for="GET-name">Name:</label>
<input id="GET-name" type="text" name="name">
<input type="submit" value="sendGET">
</form>
</body>
</html>
ファイルの場所:
src/formgoji/main.go
src/formgoji/public/index.html
出力 - ターミナル ウィンドウで開始します。
$ go run main.go
2014/12/22 14:38:40.984448 Starting Goji on [::]:8000
2014/12/22 14:38:48.789214 [xxxx/yyyy-000001] Started GET "/" from 127.0.0.1:51580
2014/12/22 14:38:48.789332 [xxxx/yyyy-000001] Returning 304 in 74.8µs
2014/12/22 14:39:11.239039 [xxxx/yyyy-000002] Started GET "/?name=test" from 127.0.0.1:51580
2014/12/22 14:39:11.239149 [xxxx/yyyy-000002] Returning 304 in 66.489µs
同様の質問がstackoverflowにありました: parse-input-from-html-form-in- golang これは、この例では欠落しています。