Conditions | 5 |
Total Lines | 18 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | package fun |
||
18 | func GetImageURL(category string) (string, error) { |
||
19 | resp, err := http.Get(fmt.Sprintf("https://botimages.realpha.ru/?category=%v", category)) |
||
20 | if err != nil && resp.StatusCode == http.StatusOK { |
||
21 | fmt.Printf("Getting image url error: %v", err) |
||
22 | return "", errors.New("getting image url error") |
||
23 | } |
||
24 | |||
25 | var result ImageResponse |
||
26 | |||
27 | err = json.NewDecoder(resp.Body).Decode(&result) |
||
28 | if err != nil { |
||
29 | return "", err |
||
30 | } |
||
31 | |||
32 | if result.Success { |
||
33 | return fmt.Sprintf("https://botimages.realpha.ru/%v", result.ImageURL), nil |
||
34 | } |
||
35 | return "", errors.New("wrong data") |
||
36 | } |
||
53 |