Skip to content

Instantly share code, notes, and snippets.

@zhichenghou
Created April 24, 2015 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhichenghou/df8117264854be82c2b8 to your computer and use it in GitHub Desktop.
Save zhichenghou/df8117264854be82c2b8 to your computer and use it in GitHub Desktop.
ezfm 飞鱼秀 回放
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func getDatas() []interface{} {
resp, err := http.Get("http://ezfm.china-plus.net/index.php?m=index&a=cat_list&cid=224")
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var f interface{}
e := json.Unmarshal(body, &f)
if e != nil {
fmt.Println(err)
}
m := f.(map[string]interface{})
return m["data"].([]interface{})
}
func handler(w http.ResponseWriter, r *http.Request) {
datas := getDatas()
html := `
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<h2> EZFM 飞鱼秀 回放 </h2>
<table cellspacing="8">
<tr>
<th>Title</th>
<th>Url</th>
<th>Update time</th>
</tr>
`
for _, v := range datas {
data := v.(map[string]interface{})
html += `
<tr>
<td>` + data["title"].(string) + `</td>
<td><a href=` + data["url"].(string) + ">" + data["url"].(string) + "</a>" + `</td>
<td>` + data["update_time"].(string) + `</td>
</tr>
`
}
html += `
</table>
</body>
</html>
`
fmt.Fprintf(w, html)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment