Skip to content

Instantly share code, notes, and snippets.

@liangchaoboy
Created May 14, 2018 16:03
Show Gist options
  • Save liangchaoboy/7e9902cfe186d51b6419f85401a92fcd to your computer and use it in GitHub Desktop.
Save liangchaoboy/7e9902cfe186d51b6419f85401a92fcd to your computer and use it in GitHub Desktop.
get_duration
package qiniustg
import (
"config"
"fmt"
"io/ioutil"
"net/http"
"encoding/json"
"strconv"
)
type medie struct {
Format fort `json:"format"`
}
type fort struct {
Duration string `json:"duration"`
}
func HttpReq(recordsCh, retCh chan string, _ config.Config) {
for url := range recordsCh {
resp, err := http.Get(url+"?avinfo")
if err != nil{
//handle error
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil{
// handle error
}
//fmt.Println(string(body))
var result medie
json.Unmarshal(body, &result)
var f float64
f,_ = strconv.ParseFloat(result.Format.Duration, 64)
fmt.Printf("%s\t%d\n",url, int(f))
retCh <- fmt.Sprintf("%s\t%d", url, int(f))
resp.Body.Close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment