Go 包用于轻松渲染 JSON、XML、二进制数据和 HTML 模板响应。
func main() { r := render.New() mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { w.Write([]byte("欢迎访问子页面。")) }) mux.HandleFunc("/data", func(w http.ResponseWriter, req *http.Request) { r.Data(w, http.StatusOK, []byte("这里有一些二进制数据。")) }) mux.HandleFunc("/text", func(w http.ResponseWriter, req *http.Request) { r.Text(w, http.StatusOK, "这里是纯文本") }) mux.HandleFunc("/json", func(w http.ResponseWriter, req *http.Request) { r.JSON(w, http.StatusOK, map[string]string{"hello": "json"}) })
mux.HandleFunc("/jsonp", func(w http.ResponseWriter, req *http.Request) { r.JSONP(w, http.StatusOK, "callbackName", map[string]string{"hello": "jsonp"}) }) mux.HandleFunc("/xml", func(w http.ResponseWriter, req *http.Request) { r.XML(w, http.StatusOK, ExampleXml{One: "hello", Two: "xml"})
暂无开放 Issues,或尚未同步最近议题。