package configloader import ( "errors" "net/http" "strconv" ) // Validates an institution ID. // A valid institution ID returns a HTTP 200 response code when queried // + "/institution/" + institution_id. // Returns either the entered instance URL or an error. func ValidateInstitutionId(institutionId int, instanceUrl string) (int, error) { if institutionId < 1 { return 0, errors.New("Institution ID cannot be negative") } resp, err := http.Get(instanceUrl + "/institution/" + strconv.Itoa(institutionId)) if err != nil { return 0, err } if resp.StatusCode != 200 { return 0, errors.New("The institution page does not respond with HTTP 200, the institution does not seem to exist") } return institutionId, nil }