英文:
Make a web app in Go?
问题
你好!以下是你要翻译的内容:
如何使用Go创建一个Web应用程序?
是否有一种方法可以像PHP和HTML一样交替使用Go代码和HTML?
更具体地说,我想知道如何在Web浏览器中显示我的PrintLn输出,并如何从HTML表单字段接受输入?
英文:
How can I make a web app in Go?
Is there a way I can interchangeably use Go code and HTML like with PHP and HTML?
More specifically, what I want to know is how to get my PrintLn output to show in a web browser and how to accept input from HTML form fields?
答案1
得分: 6
你无法嵌入Go和HTML(由于很多原因),但你可以使用Go的html/template包(http://golang.org/pkg/html/template/)从你的HTTP处理程序生成HTML页面。
我建议阅读http://golang.org/doc/articles/wiki/,并在Web服务器端使用http://www.gorillatoolkit.org/(路由、cookie等)。
英文:
You can't embed Go & HTML (for many, many reasons) but you can use Go's html/template package (http://golang.org/pkg/html/template/) to generate a HTML page from your HTTP handlers.
I'd suggest reading http://golang.org/doc/articles/wiki/ and using http://www.gorillatoolkit.org/ (routes, cookies, etc) for the web server side
答案2
得分: 0
你需要在Go语言中设置一个Web服务器,并将HTTP请求/响应作为输入/输出进行处理。关于Go Web框架已经有一个有用的答案。链接
如果你不想在浏览器窗口中显示UI,你将需要绑定自己的HTML引擎。为此,你可以查看像walk这样的UI框架,它内置了基于IE的Web视图,或者像go-webkit这样的引擎绑定,它构建了一个自定义的Web视图。
英文:
You need to setup a web server in go and process http request/response as input/output. There is already an answer about go web frameworks which would be helpful. link
If you don't want your ui to show in a browser window, you will have to bind your own html engine. For that purpose you can look at ui frameworks like walk which has ie based webview builtin or engine bindings like go-webkit which builds a custom webview.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论