From b3e2dc9459248b7acfe4cd725b644f937dafbeaf Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Thu, 13 Jul 2017 22:24:55 +1000 Subject: [PATCH] livecast handler demo data ready. --- livecast.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 1 + 2 files changed, 54 insertions(+) create mode 100644 livecast.go diff --git a/livecast.go b/livecast.go new file mode 100644 index 0000000..2ec8d7b --- /dev/null +++ b/livecast.go @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + "html/template" + "io/ioutil" + "log" + "net/http" +) + +type liveCast struct { + Youtube string + Title string + Description string +} + +func liveCastHandler(w http.ResponseWriter, r *http.Request) { + cast := liveCast{} + cast.Youtube = "https://www.youtube.com/embed/T3-ueqivO0g" + cast.Title = "大学联盟活动日" + cast.Description = ` +当地时间7月12日,伊利诺伊州中部地区联邦检察官办公室发布公告称,综合各种证据,负责调查案件的执法人员相信章莹颖已经死亡。 + +  美国司法部网站12日发布消息,美国联邦大陪审团当天正式起诉涉嫌绑架中国访问学者章莹颖的嫌疑人布伦特·克里斯滕森(Brendt Christensen),原定14日进行的预审取消,提审日期待定。 +  如罪名成立,嫌疑人布伦特·克里斯滕森将面临终身监禁的最高刑罚。目前美国警方仍在就此案进行调查。 + +  伊利诺伊州乌尔班纳(Urbana)的一个联邦大陪审团星期三决定起诉涉嫌绑架中国学者章莹颖的一名男子。` + + cast.youtubeVideo(w, r) +} + +func (m liveCast) youtubeVideo(w http.ResponseWriter, r *http.Request) { + tTest := template.New("livecast") + str, err := ioutil.ReadFile("spa/livecast.html") + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, "Formating information not available.") + return + } + tTest, err = tTest.Parse(string(str)) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, "Formating instruction invalid") + return + } + + err = tTest.Execute(w, m) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, "Monkey runs into our computer room...") + log.Println("ERROR: Template execution on spa/Edit, failed \n" + err.Error()) + } +} diff --git a/main.go b/main.go index 94b6317..2a39867 100644 --- a/main.go +++ b/main.go @@ -65,6 +65,7 @@ func setupHTTPHandler() { http.HandleFunc("/crmpixel.png", crmpixel) //tracking pixel. http.HandleFunc("/crmcache", crmcache) http.HandleFunc("/spa/editprofile", spaEditProfile) + http.HandleFunc("/spa/livecast", liveCastHandler) http.ListenAndServe(":65500", nil) }