Created
May 14, 2018 16:03
-
-
Save liangchaoboy/7e9902cfe186d51b6419f85401a92fcd to your computer and use it in GitHub Desktop.
get_duration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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