Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Respond

respond Text, HTML, XML, JSON, JSONP data to http.ResponseWriter

Godoc

Quick start

package main

import (
    "net/http"
    "github.com/gookit/respond"
)

func main() {
    // config and init the default Responder
    respond.Initialize(func(opts *respond.Options) {
        opts.TplLayout = "two-column.tpl"
        opts.TplViewsDir = "templates"
    })
    
    http.HandleFunc("/json", func(w http.ResponseWriter, r *http.Request) {
        respond.JSON(w, 200, map[string]string{
            "name": "tom",
        })
    })
    
    http.HandleFunc("/xml", func(w http.ResponseWriter, r *http.Request) {
        respond.XML(w, 200, map[string]string{
            "name": "tom",
        })
    })
    
    http.HandleFunc("/html", func(w http.ResponseWriter, r *http.Request) {
        respond.HTML(w, 200, "home.tpl", map[string]string{
            "name": "tom",
        })
    })
    
    http.ListenAndServe(":8080", nil)
}

Create new

package main

import (
    "net/http"
    "github.com/gookit/respond"
)

func main() {
    render := respond.New(func(opts *respond.Options) {
        opts.TplLayout = "two-column.tpl"
        opts.TplViewsDir = "templates"
    })
    render.Initialize()
    
    // usage
    http.HandleFunc("/json", func(w http.ResponseWriter, r *http.Request) {
        render.JSON(w, 200, map[string]string{
            "name": "tom",
        })
    })
    http.HandleFunc("/html", func(w http.ResponseWriter, r *http.Request) {
        render.HTML(w, 200, "home.tpl", map[string]string{
            "name": "tom",
        })
    })
    
}

Reference

License

MIT

About

respond Text, HTML, XML, JSON, JSONP data to http.ResponseWriter. 响应不同格式的数据到HTTP客户端

Topics

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.