我想使用Go返回我已经拥有的XML响应

问题描述 投票:0回答:1

我想打印出我已经做过的xml响应,而不是问好打印出整个响应的人都知道我该怎么做?


import (
    "fmt"
    "net/http"
)

func main() {
 http.HandleFunc("/hello", hello)
    http.ListenAndServe(":9090", nil)
}


func hello(w http.ResponseWriter, req *http.Request) {
      w.Header().Set("Content-Type", "application/xml")

  fmt.Fprintf(w, "hello\n")
}
go mocking stub
1个回答
0
投票

假设您要构建一个XML文档,例如

<Greeting><text>hello</text></Greeting>

这可以使用encoding/xml包来完成。

encoding/xml
© www.soinside.com 2019 - 2024. All rights reserved.