【发布时间】:2017-05-17 02:15:45
【问题描述】:
请看一下我的两个文件 main.go 和 index.html。 我从 Goji 网络微框架开始。在Goji web framework. 查找片段
在我的示例中,我可以在@Localhost8000 看到 HTML 表单网页 index.html 我可以在输入字段中输入例如“test”并按下提交按钮。 在终端输出中,我可以看到它是从 127.0.0.1:51580 发送的:"Started GET "/?name=test"
如何在变量中获取对 golang 的 HTML GET 表单请求? 我认为它将与 goji.Get 一起使用。我尝试了几种方法,但我让它不运行。 如果有人可以给我提示或sn-p,我很高兴。我还在学习 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()
}
文件索引.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 这个例子我无法运行。我认为这与你的文件所在的位置有关 你的@localhost 是如何定义的。在这个例子中没有这个。
【问题讨论】:
-
您的主要问题没有意义。你能改写一下,或者问一些更具体的问题吗?