forRewindService.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package edge_service
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "iot_manager_service/config"
  6. "net/http"
  7. "net/url"
  8. )
  9. // Rewind 回放记录
  10. type ForRewindService struct {
  11. }
  12. // getRewindApi 公用请求接口
  13. func (f *ForRewindService) getRewindApi(url string) (string, error) {
  14. fmt.Printf("url = %v", url)
  15. method := "GET"
  16. client := &http.Client{}
  17. req, err := http.NewRequest(method, url, nil)
  18. if err != nil {
  19. fmt.Println(err)
  20. return "", nil
  21. }
  22. res, err := client.Do(req)
  23. if err != nil {
  24. fmt.Println(err)
  25. return "", nil
  26. }
  27. defer res.Body.Close()
  28. body, err := ioutil.ReadAll(res.Body)
  29. if err != nil {
  30. fmt.Println(err)
  31. return "", nil
  32. }
  33. fmt.Println(string(body))
  34. return string(body), err
  35. }
  36. func (f *ForRewindService) GetRewindText(streamId string, date string) (string, error) {
  37. //fmt.Printf("streamId = %v", streamId)
  38. cfg := config.Instance()
  39. api := cfg.Foreign.SecurityRewindUrl + "/list/%v/%v"
  40. url2 := fmt.Sprintf(api, (streamId), url.QueryEscape(date))
  41. //fmt.Printf("url2 = %v", url2)
  42. //return "", nil
  43. return f.getRewindApi(url2)
  44. }