我使用Goji框架运行了一些东西:
package main
import (
"fmt"
"net/http"
"github.com/zenazn/goji"
"github.com/zenazn/goji/web"
)
func hello(c web.C, w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", c.URLParams["name"])
}
func main() {
goji.Get("/hello/:name", hello)
goji.Serve()
}
Run Code Online (Sandbox Code Playgroud)
我希望有人可以帮我做的是弄清楚提交HTML表单时如何将该数据发送到Golang代码.
因此,如果有一个带有name属性的输入字段,并且name的值是name,并且用户在那里键入一个名称并提交,那么在表单提交页面上,Golang代码将打印hello,name.
这是我能想到的:
package main
import(
"fmt"
"net/http"
"github.com/zenazn/goji"
"github.com/zenazn/goji/web"
)
func hello(c web.C, w http.ResponseWriter, r *http.Request){
name := r.PostFormValue("name")
fmt.Fprintf(w, "Hello, %s!", name)
}
func main(){
goji.Handle("/hello/", hello)
goji.Serve()
}
Run Code Online (Sandbox Code Playgroud)
这是我的hello.html文件:
在身体里:
<form action="" method="get">
<input type="text" name="name" />
</form>
Run Code Online (Sandbox Code Playgroud)
如何连接hello.html到hello.goGolang代码获取输入中的内容并在表单提交页面中返回hello,name?
我非常感谢任何帮助!
如何通过白色空间分割字符串无论白色空间有多长?
例如,从以下字符串:
"the quick brown fox jumps over the lazy dog"
Run Code Online (Sandbox Code Playgroud)
我会得到一个数组
['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'];
Run Code Online (Sandbox Code Playgroud) 这个脚本在play.golang.org中没有错误地编译:http://play.golang.org/p/Hlr-IAc_1f
但是当我在我的机器上运行时,比我预期的要长得多,终端中没有任何事情发生.
我想要构建的是PartOfSpeech Tagger.
我认为最长的部分是将lexicon.txt加载到地图中,然后将每个单词与每个单词进行比较,以查看它是否已经在词典中被标记.词典只包含动词.但不是每个词都需要检查,看它是否是一个动词.
更大的问题是我不知道如何判断一个单词是否是一个动词,其中包含副词,形容词等简单的启发式动词.