Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1099355
  • 博文数量: 187
  • 博客积分: 1156
  • 博客等级: 少尉
  • 技术积分: 2163
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-16 15:01
个人简介

go!go!go!

文章分类

全部博文(187)

文章存档

2024年(1)

2023年(11)

2022年(13)

2021年(15)

2020年(38)

2019年(3)

2018年(6)

2016年(1)

2015年(16)

2014年(13)

2013年(24)

2012年(46)

分类: LINUX

2015-05-19 19:13:59


  1. package main
  2. import "fmt"
  3. import "net/http"
  4. import "io/ioutil"
  5. import "strings"
  6. import "bufio"
  7. func httpGet() {
  8. resp, err := http.Get("")
  9. if err != nil {
  10. // handle error
  11. }
  12. defer resp.Body.Close()
  13. body, err := ioutil.ReadAll(resp.Body)
  14. if err != nil {
  15. // handle error
  16. }
  17. src := string(body)
  18. //fmt.Println(src)
  19. sReader := strings.NewReader(string(src))
  20. bReader := bufio.NewScanner(sReader)
  21. bReader.Split(bufio.ScanLines)
  22. for bReader.Scan() {
  23. line := bReader.Text()
  24. if !strings.HasPrefix(line, "#") {
  25. tsFileName := line
  26. fmt.Println(tsFileName)
  27. tsFileUrl := fmt.Sprintf("%s", tsFileName)
  28. fmt.Println(tsFileUrl)
  29. downloadTS(tsFileUrl)
  30. }
  31. }
  32. }
  33. func downloadTS(tsFileUrl string) {
  34. fmt.Println("downloading: ", tsFileUrl)
  35. resp, err := http.Get(tsFileUrl)
  36. if err != nil {
  37. fmt.Println("download ts ", tsFileUrl, "failed,", err)
  38. return
  39. }
  40. defer resp.Body.Close()
  41. //fmt.Println(resp.Body)
  42. }
  43. func main() {
  44. httpGet()
  45. //fmt.Printf("hello, world\n")
  46. }

阅读(6276) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~