| 937 | return r, nil |
| 938 | } |
| 939 | |
| 940 | func (a *API) get(path string) error { |
| 941 | url := fmt.Sprintf(path, a.source) |
| 942 | resp, err := a.Client.Get(url) |
| 943 | if err != nil { |
| 944 | return err |
| 945 | } |
| 946 | defer resp.Body.Close() |
| 947 | |
| 948 | if resp.StatusCode == http.StatusInternalServerError { |
| 949 | return ErrInternalError |
| 950 | } |
| 951 | |
| 952 | if resp.StatusCode != http.StatusOK { |
| 953 | return errors.New(http.StatusText(resp.StatusCode)) |
| 954 | } |
| 955 | |
| 956 | r := &Result{} |
| 957 | if err = json.NewDecoder(resp.Body).Decode(r); err != nil { |
| 958 | return err |
| 959 | } |
| 960 | |
| 961 | if !r.Result { |
| 962 | return errors.New(r.Message) |
| 963 | } |
| 964 | |
| 965 | return nil |
| 966 | } |
| 967 | |
| 968 | // StartMeasure starts measurement |