package homekit import ( "encoding/json" "errors" "io/ioutil" "net/http" "strconv" "time" ) func isJSON(s string) bool { var js map[string]interface{} return json.Unmarshal([]byte(s), &js) == nil } func tryGet(url string) (string, error) { client := http.Client{ Timeout: 10 * time.Second, } resp, err := client.Get(url) if err != nil { return "", err } if resp.StatusCode != 200 { return "", errors.New("Server side return status code " + strconv.Itoa(resp.StatusCode)) } content, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } return string(content), nil }