package sdApi4 import ( "bytes" "net/http" "strconv" ) var ( apiKey string ) // example is here: https://devel.mephi.ru/dyokunev/cps-api/src/bf961a7c6732fd3bc146d260b22848d4263ebe3f/app/init.go#L302 func SetApiKey(newApiKey string) { apiKey = newApiKey } func getPhoto(parameterName, parameterValue string) ([]byte, error) { client := &http.Client{} req, _ := http.NewRequest("GET", "https://sd.mephi.ru/api/4/get_photo.jpeg", nil) q := req.URL.Query() q.Add("api_key", apiKey) q.Add(parameterName, parameterValue) req.URL.RawQuery = q.Encode() response, err := client.Do(req) if err != nil { return nil, err } defer response.Body.Close() var bytesArray []byte buf := bytes.NewBuffer(bytesArray) _, err = buf.ReadFrom(response.Body) if err != nil { return nil, err } return buf.Bytes(), nil } // example is here: https://devel.mephi.ru/dyokunev/cps-api/src/bf961a7c6732fd3bc146d260b22848d4263ebe3f/app/controllers/people.go#L92 func GetPhoto(personId int) ([]byte, error) { return getPhoto("person_id", strconv.Itoa(personId)) } func GetPhotoByEmpGUID(empGUID int) ([]byte, error) { return getPhoto("e_id", strconv.Itoa(empGUID)) }