在一个非常基本的手写网页(没有 js、样式表等)中,我有一些静态 html,其中有一个部分看起来像这样。
<li style="font-size:200%; margin-bottom:3vh;">
<a href="http://192.168.1.122:8000">
Reload HMI
</a>
</li>
我正在使用 Go 的 http.ListenAndServe 来提供页面。结果是这样的:
<li style="font-size:200%!;(MISSING) margin-bottom:3vh;">
<a href="http://192.168.1.122:8000">
Reload HMI
</a>
</li>
请注意更改后的样式属性。
服务器实现也很初级。它作为 goroutine 启动:
// systemControlService provides pages on localhost:8003 that
// allow reboots, shutdowns and restoring configurations.
func systemControlService() {
info("Launching system control service")
http.HandleFunc("/", controlPage)
log.Fatal(http.ListenAndServe(":8003", nil))
}
// loadPage serves the page named by title
func loadPage(title string) ([]byte, error) {
filename := "__html__/" + title + ".html"
info(filename + " requested")
content, err := ioutil.ReadFile(filename)
if err != nil {
info(fmt.Sprintf("error reading file: %v", err))
return nil, err
}
info(string(content))
return content, nil
}
// controlPage serves controlpage.html
func controlPage(w http.ResponseWriter, r *http.Request) {
p, _ := loadPage("controlpage")
fmt.Fprintf(w, string(p))
}
在上面的func 中loadPage(),info是一个日志记录调用。对于调试,我在返回controlpage.html. 日志条目显示它在那个时候没有被破坏,所以问题几乎必须在 ListenAndServe 中。
我在 Go 文档中找不到任何http似乎适用的内容。我不知道这里发生了什么。任何帮助表示赞赏。
紫衣仙女
波斯汪
红糖糍粑
相关分类