Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

78 linhas
1.9KB

  1. package main
  2. import (
  3. "fmt"
  4. "html/template"
  5. "io/ioutil"
  6. "log"
  7. "net/http"
  8. "net/url"
  9. )
  10. type crmdLiveCast struct {
  11. crmdEntityBase
  12. Youtube string `json:"youtube,omitempty"`
  13. Description string `json:"description,omitempty"`
  14. }
  15. func spaLiveCastHandler(w http.ResponseWriter, r *http.Request) {
  16. castID := ""
  17. q, err := url.ParseQuery(r.URL.RawQuery)
  18. if err == nil {
  19. castIDs, ok := q["id"]
  20. if ok {
  21. castID = castIDs[0]
  22. }
  23. }
  24. if castID == "" {
  25. responseDefaultLiveCast(w)
  26. return
  27. }
  28. //castID = "5967812b87eb10564"
  29. entity, err := crmGetEntity("Livecast", castID)
  30. if err != nil || entity == nil {
  31. response404Handler(w)
  32. return
  33. }
  34. cast := entity.(crmdLiveCast)
  35. cast.youtubeVideo(w)
  36. }
  37. func (m crmdLiveCast) youtubeVideo(w http.ResponseWriter) {
  38. tTest := template.New("livecast")
  39. str, err := ioutil.ReadFile("spa/livecast.html")
  40. if err != nil {
  41. w.WriteHeader(http.StatusInternalServerError)
  42. fmt.Fprintf(w, "Formating information not available.")
  43. return
  44. }
  45. tTest, err = tTest.Parse(string(str))
  46. if err != nil {
  47. w.WriteHeader(http.StatusInternalServerError)
  48. fmt.Fprintf(w, "Formating instruction invalid")
  49. return
  50. }
  51. err = tTest.Execute(w, m)
  52. if err != nil {
  53. w.WriteHeader(http.StatusInternalServerError)
  54. fmt.Fprintf(w, "Monkey runs into our computer room...")
  55. log.Println("ERROR: Template execution on spa/Edit, failed \n" + err.Error())
  56. }
  57. }
  58. func responseDefaultLiveCast(w http.ResponseWriter) {
  59. cast := crmdLiveCast{}
  60. cast.Youtube = "https://www.youtube.com/embed/8r9zR27Kzho"
  61. cast.Name = "暂无直播"
  62. cast.Description = `
  63. 直播活动,和校友会活动息息相关,方便在不同地域的校友积极参加,同时留下宝贵的影响资料,供后来的校友们参考。在没有直播的情况下, 校友会随机选取哈工大的宣传片,校友们的个人简介,以及校友会的宣传片放映。
  64. `
  65. cast.youtubeVideo(w)
  66. }