Conditions | 4 |
Total Lines | 16 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | package location |
||
35 | func New(user string, locationName string) (result LocationResultData, err error) { |
||
36 | resp, err := http.Get(fmt.Sprintf("http://api.geonames.org/searchJSON?q=%v&maxRows=1&username=%v", locationName, user)) |
||
37 | if err != nil { |
||
38 | return result, err |
||
39 | } |
||
40 | |||
41 | err = json.NewDecoder(resp.Body).Decode(&result) |
||
42 | if err != nil { |
||
43 | return result, err |
||
44 | } |
||
45 | |||
46 | if len(result.Geonames) == 0 { |
||
47 | return result, errors.New("City not found") |
||
48 | } |
||
49 | |||
50 | return result, nil |
||
51 | } |
||
52 |