我正在尝试解码golang中的一些json,但有些字段没有被解码.在这里查看浏览器中运行的代码:
我究竟做错了什么 ?我只需要MX记录,所以我没有定义其他字段.据我所知,你不需要定义你不使用/不需要的字段.
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
import "encoding/json"
func main() {
body := `
{"response": {
"status": "SUCCESS",
"data": {
"mxRecords": [
{
"value": "us2.mx3.mailhostbox.com.",
"ttl": 1,
"priority": 100,
"hostName": "@"
},
{
"value": "us2.mx1.mailhostbox.com.",
"ttl": 1,
"priority": 100,
"hostName": "@"
},
{
"value": "us2.mx2.mailhostbox.com.",
"ttl": 1,
"priority": 100,
"hostName": "@"
}
],
"cnameRecords": [
{
"aliasHost": "pop.a.co.uk.",
"canonicalHost": "us2.pop.mailhostbox.com."
},
{
"aliasHost": "webmail.a.co.uk.",
"canonicalHost": …Run Code Online (Sandbox Code Playgroud) 我想知道为什么函数不能使用同类型的函数?请参阅以下伪函数.
游乐场:http://play.golang.org/p/ZG1jU8H2ZJ
package main
type typex struct {
email string
id string
}
type typey struct {
email string
id string
}
func useType(t *typex) {
// do something
}
func main() {
x := &typex{
id: "somethng",
}
useType(x) // works
y := &typey{
id: "something",
}
useType(y) // doesn't work ??
}
Run Code Online (Sandbox Code Playgroud) 我通过epel在redhat服务器上安装了golang.我正在尝试分析恐慌日志,但我找不到日志的存储位置.任何提示?/ var/log中没有跟踪
func main() {
http.HandleFunc("/", panicRecover(test))
log.Fatal(http.ListenAndServe(":80", nil))
}
func test(){
out, err := exec.Command("echo ", "something").Output()
if err != nil {
log.Panic(err)
}
}
func panicRecover(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
defer func() {
if r := recover(); r != nil {
log.Printf("PANIC RECOVERED:%s\n", r)
}
}()
f(w, r)
}
Run Code Online (Sandbox Code Playgroud)