- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
更新 1.1
在收到有关更改处理程序路径的有用反馈后,我在我的应用程序中使用了该反馈,但奇怪的是,我仍然收到一些错误反馈。我正在尝试自己弄清楚,但我想我可以与大家分享。这也是我取消现在给出的答案的原因。还有一些答案现在让我感到困惑,无法理解这将如何为我工作。
package main
import (
"net/http" // Package http provides HTTP client and server implementations.
)
func main(){
webHost()
}
func webHost(){
// Ik heb hier later nog een mapje voor de html pagina's toegevoegd.
http.Handle("/go", http.FileServer(http.Dir("./1_Go_Files")))
http.Handle("/html", http.FileServer(http.Dir("./2_Html_Pages")))
http.Handle("/storage", http.FileServer(http.Dir("./3_Json_Storage")))
// -----------------------------------------------------------------
http.HandleFunc("/homepage", Homehandler)
http.HandleFunc("/selectiepagina", Selectiehandler)
http.HandleFunc("/userinputpagina", Userinputhandler)
http.HandleFunc("/bestelnrpagina", Bestelnrhandler)
http.HandleFunc("/statuspagina", Statushandler)
//FileServer returns a handler that serves HTTP requests with the contents of the file system rooted at root..
http.Handle("/4_Css_Styling/", http.StripPrefix("/4_Css_Styling/", http.FileServer(http.Dir("css")))) // css styling map.
http.Handle("/5_Pizza_Img/", http.StripPrefix("/5_Pizza_Img/", http.FileServer(http.Dir("img")))) // image mapje.
}
所以这里出现了新的 panic (对不起,文字墙,我不确定要遗漏什么,所以我只是复制粘贴这里的所有内容:
2018/11/12 10:07:11 http: panic serving [::1]:58084: runtime error: invalid memory address or nil pointer dereference
goroutine 4 [running]:
net/http.(*conn).serve.func1(0xc0000de000)
C:/tools/go/src/net/http/server.go:1746 +0xd7
panic(0x73a9c0, 0xa34b30)
C:/tools/go/src/runtime/panic.go:513 +0x1c7
html/template.(*Template).escape(0x0, 0x0, 0x0)
C:/tools/go/src/html/template/template.go:95 +0x35
html/template.(*Template).Execute(0x0, 0x7f7580, 0xc0001160e0, 0x71ac40, 0x7f5300, 0xc000106120, 0x3)
C:/tools/go/src/html/template/template.go:119 +0x36
main.Homehandler(0x7f9f60, 0xc0001160e0, 0xc000124000)
C:/Users/Taavetti/Documents/Go/Sources/src/Projects/VillaBrutus_Main/1_Go_Files/0_Homepagina.go:14 +0xc8
net/http.HandlerFunc.ServeHTTP(0x7b3ca8, 0x7f9f60, 0xc0001160e0, 0xc000124000)
C:/tools/go/src/net/http/server.go:1964 +0x4b
net/http.(*ServeMux).ServeHTTP(0xa438e0, 0x7f9f60, 0xc0001160e0, 0xc000124000)
C:/tools/go/src/net/http/server.go:2361 +0x12e
net/http.serverHandler.ServeHTTP(0xc00004b040, 0x7f9f60, 0xc0001160e0, 0xc000124000)
C:/tools/go/src/net/http/server.go:2741 +0xb2
net/http.(*conn).serve(0xc0000de000, 0x7fa120, 0xc0000320c0)
C:/tools/go/src/net/http/server.go:1847 +0x64d
created by net/http.(*Server).Serve
C:/tools/go/src/net/http/server.go:2851 +0x2fc
2018/11/12 10:07:11 http: panic serving [::1]:58087: runtime error: invalid memory address or nil pointer dereference
goroutine 19 [running]:
net/http.(*conn).serve.func1(0xc00004cf00)
C:/tools/go/src/net/http/server.go:1746 +0xd7
panic(0x73a9c0, 0xa34b30)
C:/tools/go/src/runtime/panic.go:513 +0x1c7
html/template.(*Template).escape(0x0, 0x0, 0x0)
C:/tools/go/src/html/template/template.go:95 +0x35
html/template.(*Template).Execute(0x0, 0x7f7580, 0xc0001161c0, 0x71ac40, 0x7f5300, 0xc0001061e0, 0x3)
C:/tools/go/src/html/template/template.go:119 +0x36
main.Homehandler(0x7f9f60, 0xc0001161c0, 0xc000126000)
C:/Users/Taavetti/Documents/Go/Sources/src/Projects/VillaBrutus_Main/1_Go_Files/0_Homepagina.go:14 +0xc8
net/http.HandlerFunc.ServeHTTP(0x7b3ca8, 0x7f9f60, 0xc0001161c0, 0xc000126000)
C:/tools/go/src/net/http/server.go:1964 +0x4b
net/http.(*ServeMux).ServeHTTP(0xa438e0, 0x7f9f60, 0xc0001161c0, 0xc000126000)
C:/tools/go/src/net/http/server.go:2361 +0x12e
net/http.serverHandler.ServeHTTP(0xc00004b040, 0x7f9f60, 0xc0001161c0, 0xc000126000)
C:/tools/go/src/net/http/server.go:2741 +0xb2
net/http.(*conn).serve(0xc00004cf00, 0x7fa120, 0xc00004e240)
C:/tools/go/src/net/http/server.go:1847 +0x64d
created by net/http.(*Server).Serve
C:/tools/go/src/net/http/server.go:2851 +0x2fc
2018/11/12 10:07:11 http: panic serving [::1]:58088: runtime error: invalid memory address or nil pointer dereference
goroutine 37 [running]:
net/http.(*conn).serve.func1(0xc000172000)
C:/tools/go/src/net/http/server.go:1746 +0xd7
panic(0x73a9c0, 0xa34b30)
C:/tools/go/src/runtime/panic.go:513 +0x1c7
html/template.(*Template).escape(0x0, 0x0, 0x0)
C:/tools/go/src/html/template/template.go:95 +0x35
html/template.(*Template).Execute(0x0, 0x7f7580, 0xc0001162a0, 0x71ac40, 0x7f5300, 0xc000106360, 0x3)
C:/tools/go/src/html/template/template.go:119 +0x36
main.Homehandler(0x7f9f60, 0xc0001162a0, 0xc000124100)
C:/Users/Taavetti/Documents/Go/Sources/src/Projects/VillaBrutus_Main/1_Go_Files/0_Homepagina.go:14 +0xc8
net/http.HandlerFunc.ServeHTTP(0x7b3ca8, 0x7f9f60, 0xc0001162a0, 0xc000124100)
C:/tools/go/src/net/http/server.go:1964 +0x4b
net/http.(*ServeMux).ServeHTTP(0xa438e0, 0x7f9f60, 0xc0001162a0, 0xc000124100)
C:/tools/go/src/net/http/server.go:2361 +0x12e
net/http.serverHandler.ServeHTTP(0xc00004b040, 0x7f9f60, 0xc0001162a0, 0xc000124100)
C:/tools/go/src/net/http/server.go:2741 +0xb2
net/http.(*conn).serve(0xc000172000, 0x7fa120, 0xc000110240)
C:/tools/go/src/net/http/server.go:1847 +0x64d
created by net/http.(*Server).Serve
C:/tools/go/src/net/http/server.go:2851 +0x2fc
2018/11/12 10:07:11 http: panic serving [::1]:58089: runtime error: invalid memory address or nil pointer dereference
goroutine 39 [running]:
net/http.(*conn).serve.func1(0xc0001720a0)
C:/tools/go/src/net/http/server.go:1746 +0xd7
panic(0x73a9c0, 0xa34b30)
C:/tools/go/src/runtime/panic.go:513 +0x1c7
html/template.(*Template).escape(0x0, 0x0, 0x0)
C:/tools/go/src/html/template/template.go:95 +0x35
html/template.(*Template).Execute(0x0, 0x7f7580, 0xc000116380, 0x71ac40, 0x7f5300, 0xc0001064e0, 0x3)
C:/tools/go/src/html/template/template.go:119 +0x36
main.Homehandler(0x7f9f60, 0xc000116380, 0xc000124200)
C:/Users/Taavetti/Documents/Go/Sources/src/Projects/VillaBrutus_Main/1_Go_Files/0_Homepagina.go:14 +0xc8
net/http.HandlerFunc.ServeHTTP(0x7b3ca8, 0x7f9f60, 0xc000116380, 0xc000124200)
C:/tools/go/src/net/http/server.go:1964 +0x4b
net/http.(*ServeMux).ServeHTTP(0xa438e0, 0x7f9f60, 0xc000116380, 0xc000124200)
C:/tools/go/src/net/http/server.go:2361 +0x12e
net/http.serverHandler.ServeHTTP(0xc00004b040, 0x7f9f60, 0xc000116380, 0xc000124200)
C:/tools/go/src/net/http/server.go:2741 +0xb2
net/http.(*conn).serve(0xc0001720a0, 0x7fa120, 0xc000110340)
C:/tools/go/src/net/http/server.go:1847 +0x64d
created by net/http.(*Server).Serve
C:/tools/go/src/net/http/server.go:2851 +0x2fc
2018/11/12 10:07:12 http: panic serving [::1]:58090: runtime error: invalid memory address or nil pointer dereference
goroutine 20 [running]:
net/http.(*conn).serve.func1(0xc00004cfa0)
C:/tools/go/src/net/http/server.go:1746 +0xd7
panic(0x73a9c0, 0xa34b30)
C:/tools/go/src/runtime/panic.go:513 +0x1c7
html/template.(*Template).escape(0x0, 0x0, 0x0)
C:/tools/go/src/html/template/template.go:95 +0x35
html/template.(*Template).Execute(0x0, 0x7f7580, 0xc000116460, 0x71ac40, 0x7f5300, 0xc000106660, 0x3)
C:/tools/go/src/html/template/template.go:119 +0x36
main.Homehandler(0x7f9f60, 0xc000116460, 0xc000126100)
C:/Users/Taavetti/Documents/Go/Sources/src/Projects/VillaBrutus_Main/1_Go_Files/0_Homepagina.go:14 +0xc8
net/http.HandlerFunc.ServeHTTP(0x7b3ca8, 0x7f9f60, 0xc000116460, 0xc000126100)
C:/tools/go/src/net/http/server.go:1964 +0x4b
net/http.(*ServeMux).ServeHTTP(0xa438e0, 0x7f9f60, 0xc000116460, 0xc000126100)
C:/tools/go/src/net/http/server.go:2361 +0x12e
net/http.serverHandler.ServeHTTP(0xc00004b040, 0x7f9f60, 0xc000116460, 0xc000126100)
C:/tools/go/src/net/http/server.go:2741 +0xb2
net/http.(*conn).serve(0xc00004cfa0, 0x7fa120, 0xc00004e2c0)
C:/tools/go/src/net/http/server.go:1847 +0x64d
created by net/http.(*Server).Serve
C:/tools/go/src/net/http/server.go:2851 +0x2fc
2018/11/12 10:07:12 http: panic serving [::1]:58091: runtime error: invalid memory address or nil pointer dereference
goroutine 41 [running]:
net/http.(*conn).serve.func1(0xc000172140)
C:/tools/go/src/net/http/server.go:1746 +0xd7
panic(0x73a9c0, 0xa34b30)
C:/tools/go/src/runtime/panic.go:513 +0x1c7
html/template.(*Template).escape(0x0, 0x0, 0x0)
C:/tools/go/src/html/template/template.go:95 +0x35
html/template.(*Template).Execute(0x0, 0x7f7580, 0xc0001cc000, 0x71ac40, 0x7f5300, 0xc000067290, 0x3)
C:/tools/go/src/html/template/template.go:119 +0x36
main.Homehandler(0x7f9f60, 0xc0001cc000, 0xc000124300)
C:/Users/Taavetti/Documents/Go/Sources/src/Projects/VillaBrutus_Main/1_Go_Files/0_Homepagina.go:14 +0xc8
net/http.HandlerFunc.ServeHTTP(0x7b3ca8, 0x7f9f60, 0xc0001cc000, 0xc000124300)
C:/tools/go/src/net/http/server.go:1964 +0x4b
net/http.(*ServeMux).ServeHTTP(0xa438e0, 0x7f9f60, 0xc0001cc000, 0xc000124300)
C:/tools/go/src/net/http/server.go:2361 +0x12e
net/http.serverHandler.ServeHTTP(0xc00004b040, 0x7f9f60, 0xc0001cc000, 0xc000124300)
C:/tools/go/src/net/http/server.go:2741 +0xb2
net/http.(*conn).serve(0xc000172140, 0x7fa120, 0xc000110440)
C:/tools/go/src/net/http/server.go:1847 +0x64d
created by net/http.(*Server).Serve
C:/tools/go/src/net/http/server.go:2851 +0x2fc
2018/11/12 10:07:12 http: panic serving [::1]:58092: runtime error: invalid memory address or nil pointer dereference
goroutine 22 [running]:
net/http.(*conn).serve.func1(0xc00004d040)
C:/tools/go/src/net/http/server.go:1746 +0xd7
panic(0x73a9c0, 0xa34b30)
C:/tools/go/src/runtime/panic.go:513 +0x1c7
html/template.(*Template).escape(0x0, 0x0, 0x0)
C:/tools/go/src/html/template/template.go:95 +0x35
html/template.(*Template).Execute(0x0, 0x7f7580, 0xc0001cc0e0, 0x71ac40, 0x7f5300, 0xc000067410, 0x3)
C:/tools/go/src/html/template/template.go:119 +0x36
main.Homehandler(0x7f9f60, 0xc0001cc0e0, 0xc000126200)
C:/Users/Taavetti/Documents/Go/Sources/src/Projects/VillaBrutus_Main/1_Go_Files/0_Homepagina.go:14 +0xc8
net/http.HandlerFunc.ServeHTTP(0x7b3ca8, 0x7f9f60, 0xc0001cc0e0, 0xc000126200)
C:/tools/go/src/net/http/server.go:1964 +0x4b
net/http.(*ServeMux).ServeHTTP(0xa438e0, 0x7f9f60, 0xc0001cc0e0, 0xc000126200)
C:/tools/go/src/net/http/server.go:2361 +0x12e
net/http.serverHandler.ServeHTTP(0xc00004b040, 0x7f9f60, 0xc0001cc0e0, 0xc000126200)
C:/tools/go/src/net/http/server.go:2741 +0xb2
net/http.(*conn).serve(0xc00004d040, 0x7fa120, 0xc00004e3c0)
C:/tools/go/src/net/http/server.go:1847 +0x64d
created by net/http.(*Server).Serve
C:/tools/go/src/net/http/server.go:2851 +0x2fc
同样,我仍在尝试自己解决这个问题,因为我想表明我也在为此付出努力,而不仅仅是试图从您那里得到所有答案。但如果你能帮助我朝着正确的方向前进,那将会很有帮助。
(同样,我是新用户,如果我违反了此线程中的某些规则,请在您否决此威胁后通知我,我真的很喜欢 stackoverflow,我正在尝试了解这个社区的运作方式。)
(添加了我当前的应用程序,包括错误,也许这有帮助?,请注意有一些荷兰语评论)
最佳答案
您已为 /
分配了多个处理程序。 看你的代码两次:
func webHost(){
http.Handle("/",
http.FileServer(http.Dir("./html_paginas")))
http.Handle("/", http.FileServer(http.Dir("./go_files")))
http.Handle("/", http.FileServer(http.Dir("./storage")))
//...
}
所以 http
必须在这种情况下 panic 。因此,对此的修复是:
func webHost(){
http.Handle("/html",
http.FileServer(http.Dir("./html_paginas")))
http.Handle("/go", http.FileServer(http.Dir("./go_files")))
http.Handle("/storage",
http.FileServer(http.Dir("./storage")))
//...
}
或者:
func webHost(){
http.Handle("/", http.FileServer(http.Dir("./root")))
//...
}
现在将您的 html,go,存储目录移动到 root
目录。
关于json - 更新 1.1 在文件夹中运行 Go 文件和 JSON 文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53223002/
我正在使用 go 图表库 https://github.com/wcharczuk/go-chart制作条形图。我面临的问题是标签值很长,我想将文本旋转 45 度以显示完整文本 我喜欢显示的日期格式是
我在构建一个非常简单的通过 cgo 调用 c 代码的 go 程序时遇到了问题。我的设置: $: echo $GOPATH /go $: pwd /go/src/main $: ls ctest.c
没有 C 的背景,只有 Go 的“初学者”经验,我正在尝试弄清楚 main.go 是实际需要的还是只是一个约定。 我想创建一个简单的网络 API,但有人可以为我澄清一下吗? 最佳答案 main.go
我read从 Go 1.4 开始,Go 运行时是用 Go 本身编写的(而不是用 C)。 这怎么可能?如果 Go 程序在运行时之上运行,并且运行时是 Go 程序,那么运行时是否在自身之上运行? 最佳答案
这是“Go 之旅”中的代码示例 Range and Close : package main import ( "fmt" ) func fibonacci(n int, c chan int
给定以下 go.mod 文件: module foo go 1.12 require ( github.com/bar/baz v1.0.0 github.com/rat/cat v1
我有一个 CI/CD 管道,它需要跨平台并与几个不同的管理程序一起工作。为了不必更改 Windows 和 Linux 的构建任务,我认为 Go 将是编写一次代码并在任何地方运行的好方法。然而,考虑到
我有一个 Dockerfile,用于使用 go build 编译 Go 应用程序。我进行了研究,确实建议将 go build 用于生产。 但是我找不到正确的答案来解释为什么。 我了解 go run 创
我尝试在命令提示符#Go lang 中运行该程序-但是当我键入运行“go run hello.go”命令时,我开始了 CreateFile hello.go:The system cannot fin
我正在使用“Go 编程语言”一书学习 Go。第一章介绍os.Open用于读取文件的模块。我尝试打开如下所示的 go 文件。 f, err = os.Open("helloworld.go") 我收
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题?通过 editing this post 添加详细信息并澄清问题. 2年前关闭。 Improve this
为了解决我对 goroutine 的一些误解,我去了 Go 操场跑了 this code : package main import ( "fmt" ) func other(done cha
这个问题在这里已经有了答案: Evaluate/Execute Golang code/expressions like js' eval() (5 个回答) 1年前关闭。 对于任何 go 程序,我想
这是我基本上试图从路径打印基准的代码。 这意味着,如果用户输入“/some/random/path.java”,则输出将为“path”。同样,如果用户arg为“/another/myapp.c”,则输
$ go version 1.13.3 我的文件夹结构如下: GOPATH +---src +--- my-api-server +--- my-auth-server
这个问题在这里已经有了答案: How to embed file for later parsing execution use (4 个答案) What's the best way to bun
我觉得这有点奇怪,为什么这段代码不起作用? package main import "fmt" func main() { var i, j int = 1, 2 k
go编译器执行完如下命令后的可执行文件存放在哪里? $> go run file.go 最佳答案 在 /tmp 文件夹中,如果您使用的是 unix 机器。 如果您使用的是 Windows,则在 \Us
我目前正在开始使用 Go,并且已经深入研究了有关包命名和工作区文件夹结构的注意事项。 不过,我不太确定如何根据 Go 范式正确组织我的代码。 这是我当前的结构示例,它位于 $GOPATH/src 中:
假设我有一个接受用户输入的 Lua 程序,而该输入恰好是有效的 Lua 源代码。这是在程序仍在运行时进行清理、编译和执行的。 Go 是否(或将)实现这样的事情? 最佳答案 我认为以下两个项目之间有足够
我是一名优秀的程序员,十分优秀!