Skip to content

Commit

Permalink
run gofmt and golint
Browse files Browse the repository at this point in the history
  • Loading branch information
snhilde committed Aug 17, 2020
1 parent 6ba9ec4 commit f31d1da
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions sbweather/weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
package sbweather

import (
"errors"
"strings"
"strconv"
"net/http"
"io/ioutil"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"strings"
"time"
)

var COLOR_END = "^d^"
var colorEnd = "^d^"

// routine is the main object for this package.
// err: error encountered along the way, if any
Expand Down Expand Up @@ -63,12 +63,12 @@ func New(zip string, colors ...[3]string) *routine {
return &r
}
}
r.colors.normal = "^c" + colors[0][0] + "^"
r.colors.normal = "^c" + colors[0][0] + "^"
r.colors.warning = "^c" + colors[0][1] + "^"
r.colors.error = "^c" + colors[0][2] + "^"
r.colors.error = "^c" + colors[0][2] + "^"
} else {
// If a color array wasn't passed in, then we don't want to print this.
COLOR_END = ""
colorEnd = ""
}

return &r
Expand Down Expand Up @@ -96,7 +96,7 @@ func (r *routine) Update() {
}

// Get hourly temperature.
temp, err := getTemp(r.client, r.url + "/hourly")
temp, err := getTemp(r.client, r.url+"/hourly")
if err != nil {
r.err = err
return
Expand All @@ -109,15 +109,15 @@ func (r *routine) Update() {
return
}
r.high = high
r.low = low
r.low = low
}

// Format and print current temperature.
func (r *routine) String() string {
var s string

if r.err != nil {
return r.colors.error + r.err.Error() + COLOR_END
return r.colors.error + r.err.Error() + colorEnd
}

t := time.Now()
Expand All @@ -127,7 +127,7 @@ func (r *routine) String() string {
s = "tom"
}

return fmt.Sprintf("%s%v °F (%s: %v/%v)%s", r.colors.normal, r.temp, s, r.high, r.low, COLOR_END)
return fmt.Sprintf("%s%v °F (%s: %v/%v)%s", r.colors.normal, r.temp, s, r.high, r.low, colorEnd)
}

// Get the geographic coordinates for the provided zip code.
Expand All @@ -139,7 +139,7 @@ func getCoords(client http.Client, zip string) (string, string, error) {
Output []map[string]string `json:"output"`
}

url := "https://api.promaptools.com/service/us/zip-lat-lng/get/?zip=" + zip + "&key=17o8dysaCDrgv1c"
url := "https://api.promaptools.com/service/us/zip-lat-lng/get/?zip=" + zip + "&key=17o8dysaCDrgv1c"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", "", err
Expand All @@ -157,8 +157,8 @@ func getCoords(client http.Client, zip string) (string, string, error) {
return "", "", err
}

c := coords{}
err = json.Unmarshal(body, &c)
c := coords{}
err = json.Unmarshal(body, &c)
if err != nil {
return "", "", err
}
Expand All @@ -174,7 +174,7 @@ func getCoords(client http.Client, zip string) (string, string, error) {
}

// TODO: reduce to 4 decimal points of precision
lat := c.Output[0]["latitude"]
lat := c.Output[0]["latitude"]
long := c.Output[0]["longitude"]
if lat == "" || long == "" {
return "", "", errors.New("Missing coordinates in response")
Expand All @@ -190,10 +190,10 @@ func getURL(client http.Client, lat string, long string) (string, error) {
// Properties map[string]interface{} `json:"properties"`
Properties struct {
Forecast string `json: "temperature"`
}`json:"properties"`
} `json:"properties"`
}

url := "https://api.weather.gov/points/" + lat + "," + long
url := "https://api.weather.gov/points/" + lat + "," + long
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
Expand All @@ -211,8 +211,8 @@ func getURL(client http.Client, lat string, long string) (string, error) {
return "", err
}

p := props{}
err = json.Unmarshal(body, &p)
p := props{}
err = json.Unmarshal(body, &p)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -251,8 +251,8 @@ func getTemp(client http.Client, url string) (int, error) {
return -1, errors.New("Temp: Bad Read")
}

t := temp{}
err = json.Unmarshal(body, &t)
t := temp{}
err = json.Unmarshal(body, &t)
if err != nil {
return -1, errors.New("Temp: Bad JSON")
}
Expand Down Expand Up @@ -311,8 +311,8 @@ func getForecast(client http.Client, url string) (int, int, error) {
}
// TODO: handle expired grid.

f := forecast{}
err = json.Unmarshal(body, &f)
f := forecast{}
err = json.Unmarshal(body, &f)
if err != nil {
return -1, -1, errors.New("Forecast: Bad JSON")
}
Expand All @@ -325,7 +325,7 @@ func getForecast(client http.Client, url string) (int, int, error) {

// Iterate through the list until we find the forecast for tomorrow.
var high int
var low int
var low int
for _, f := range periods {
et := f["endTime"].(string)
st := f["startTime"].(string)
Expand All @@ -345,7 +345,6 @@ func getForecast(client http.Client, url string) (int, int, error) {
return -1, -1, errors.New("Failed to determine forecast")
}


func tempConvert(val interface{}) (int, error) {
switch val.(type) {
case float64:
Expand Down

0 comments on commit f31d1da

Please sign in to comment.