Compare commits
No commits in common. "7f69e6e1c2b06e9ca3e32b808d24fd1ce1a042a7" and "fbd655b2da0de9fc952d008076c07ae7f5d72bdc" have entirely different histories.
7f69e6e1c2
...
fbd655b2da
10
.drone.yml
10
.drone.yml
@ -1,10 +0,0 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: greeting
|
||||
image: alpine
|
||||
commands:
|
||||
- echo hello
|
||||
- echo world
|
@ -2,7 +2,6 @@ package weather
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -24,10 +23,6 @@ const (
|
||||
|
||||
var (
|
||||
EndpointWeather = lib.BuildURI(OpenWeatherMapURI, "/data/2.5/weather")
|
||||
ErrUnmarshal = errors.New("unmarshaling JSON failed")
|
||||
ErrReadingResponse = errors.New("reading HTTP response failed")
|
||||
ErrRequestFailed = errors.New("HTTP request failed")
|
||||
ErrCreateRequestFailed = errors.New("failed to create new HTTP request")
|
||||
)
|
||||
|
||||
func NewClient(token string) *WeatherClient {
|
||||
@ -35,11 +30,13 @@ func NewClient(token string) *WeatherClient {
|
||||
}
|
||||
|
||||
func (c *WeatherClient) Get(loc string) (w Weather, err error) {
|
||||
var werr WeatherError
|
||||
var (
|
||||
werr WeatherError
|
||||
)
|
||||
|
||||
req, err := http.NewRequest("GET", EndpointWeather, nil)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%s: %s", ErrCreateRequestFailed, err)
|
||||
err = fmt.Errorf("failed to create new request: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -50,22 +47,22 @@ func (c *WeatherClient) Get(loc string) (w Weather, err error) {
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%s: %s", ErrRequestFailed, err)
|
||||
err = fmt.Errorf("HTTP request failed: %s", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%s: %s", ErrReadingResponse, err)
|
||||
err = fmt.Errorf("reading HTTP response failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
if resp.StatusCode != 200 {
|
||||
err = json.Unmarshal(body, &werr)
|
||||
if err != nil {
|
||||
log.Debugf("%s", body)
|
||||
err = fmt.Errorf("%s: %s", ErrUnmarshal, err)
|
||||
err = fmt.Errorf("unmarshaling JSON failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -76,7 +73,7 @@ func (c *WeatherClient) Get(loc string) (w Weather, err error) {
|
||||
err = json.Unmarshal(body, &w)
|
||||
if err != nil {
|
||||
log.Debugf("%s", body)
|
||||
err = fmt.Errorf("%s: %s", ErrUnmarshal, err)
|
||||
log.Errorf("unmarshaling JSON failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user