| | |
| | | BASIC_URL = "http://192.168.1.182:8000" |
| | | ) |
| | | |
| | | func DoRequest(request *http.Request, contentType string) ([]byte, error) { |
| | | var body []byte |
| | | request.Header.Add("Content-Type", contentType) |
| | | timeout := time.Duration(5 * time.Second) //超时时间50ms |
| | | client := &http.Client{Timeout: timeout} |
| | | resp, err := client.Do(request) |
| | | if err != nil { |
| | | return body, err |
| | | } |
| | | defer resp.Body.Close() |
| | | body, err = ioutil.ReadAll(resp.Body) |
| | | if err != nil { |
| | | return body, err |
| | | } |
| | | return body, nil |
| | | } |
| | | |
| | | //通过cameraId获取摄像机信息 |
| | | func (api DbApi) GetCameraById(cameraId string) (result Camera, err error) { |
| | | url := BASIC_URL + "/data/api-v/camera/show/" + cameraId |
| | |
| | | if err != nil { |
| | | return result, err |
| | | } |
| | | request.Header.Add("Content-Type", "application/json") |
| | | timeout := time.Duration(5 * time.Second) //超时时间50ms |
| | | client := &http.Client{Timeout: timeout} |
| | | resp, err := client.Do(request) |
| | | if err != nil { |
| | | return result, err |
| | | } |
| | | defer resp.Body.Close() |
| | | |
| | | body, err := ioutil.ReadAll(resp.Body) |
| | | body, err := DoRequest(request, "application/json") |
| | | if err != nil { |
| | | return result, err |
| | | } |