Fix nlreturn findings

This commit is contained in:
Igor Chubin 2022-12-23 16:55:14 +01:00
parent 0bf476bd41
commit bebbc32353
5 changed files with 27 additions and 0 deletions

View file

@ -99,7 +99,9 @@ func getDataFromAPI() (ret resp) {
if debug {
var out bytes.Buffer
json.Indent(&out, body, "", " ")
out.WriteTo(os.Stderr)
fmt.Print("\n\n")
}
@ -113,6 +115,7 @@ func getDataFromAPI() (ret resp) {
log.Println(err)
}
}
return
}
@ -172,5 +175,6 @@ func unmarshalLang(body []byte, r *resp) error {
if err := json.NewDecoder(&buf).Decode(r); err != nil {
return err
}
return nil
}

View file

@ -52,6 +52,7 @@ func configload() error {
if err == nil {
return json.Unmarshal(b, &config)
}
return err
}
@ -60,6 +61,7 @@ func configsave() error {
if err == nil {
return ioutil.WriteFile(configpath, j, 0o600)
}
return err
}

View file

@ -131,6 +131,7 @@ func formatTemp(c cond) string {
if explicitPlus {
return fmt.Sprintf("\033[38;5;%03dm+%d\033[0m", col, temp)
}
return fmt.Sprintf("\033[38;5;%03dm%d\033[0m", col, temp)
}
t := c.TempC
@ -158,6 +159,7 @@ func formatTemp(c cond) string {
if explicitPlus1 {
explicitPlus2 = false
}
return pad(
fmt.Sprintf("%s(%s) °%s",
color(t, explicitPlus1),
@ -188,6 +190,7 @@ func formatWind(c cond) string {
spd = (spd * 1000) / 1609
}
}
return spd
}
color := func(spd int) string {
@ -230,6 +233,7 @@ func formatWind(c cond) string {
}
}
hyphen := " - "
// if (config.Lang == "sl") {
// hyphen = "-"
@ -241,6 +245,7 @@ func formatWind(c cond) string {
if windInRightUnits(c.WindGustKmph) > windInRightUnits(c.WindspeedKmph) {
return pad(fmt.Sprintf("%s %s%s%s %s", windDir[c.Winddir16Point], cWindspeedKmph, hyphen, cWindGustKmph, unitWindString), 15)
}
return pad(fmt.Sprintf("%s %s %s", windDir[c.Winddir16Point], cWindspeedKmph, unitWindString), 15)
}
@ -248,6 +253,7 @@ func formatVisibility(c cond) string {
if config.Imperial {
c.VisibleDistKM = (c.VisibleDistKM * 621) / 1000
}
return pad(fmt.Sprintf("%d %s", c.VisibleDistKM, unitVis(config.Imperial, config.Lang)), 15)
}
@ -262,7 +268,9 @@ func formatRain(c cond) string {
rainUnit,
unitRain(config.Imperial, config.Lang),
c.ChanceOfRain), 15)
}
return pad(fmt.Sprintf("%.1f %s", rainUnit, unitRain(config.Imperial, config.Lang)), 15)
}
@ -334,7 +342,9 @@ func formatCond(cur []string, c cond, current bool) (ret []string) {
ret = append(ret, fmt.Sprintf("%v %v %v", cur[0], desc, icon[0]), fmt.Sprintf("%v %v %v", cur[1], formatTemp(c), icon[1]), fmt.Sprintf("%v %v %v", cur[2], formatWind(c), icon[2]), fmt.Sprintf("%v %v %v", cur[3], formatVisibility(c), icon[3]), fmt.Sprintf("%v %v %v", cur[4], formatRain(c), icon[4]))
} else {
ret = append(ret, fmt.Sprintf("%v %v %v", cur[0], icon[0], desc), fmt.Sprintf("%v %v %v", cur[1], icon[1], formatTemp(c)), fmt.Sprintf("%v %v %v", cur[2], icon[2], formatWind(c)), fmt.Sprintf("%v %v %v", cur[3], icon[3], formatVisibility(c)), fmt.Sprintf("%v %v %v", cur[4], icon[4], formatRain(c)))
}
return
}
@ -348,7 +358,9 @@ func justifyCenter(s string, width int) string {
s = " " + s
appendSide = 1
}
}
return s
}
@ -356,7 +368,9 @@ func reverse(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return string(r)
}
@ -379,6 +393,8 @@ func pad(s string, mustLen int) (ret string) {
} else {
ret = fmt.Sprintf("%s%s%s", toks[0], esc, pad(toks[1], mustLen-tokLen))
}
}
return
}

View file

@ -300,6 +300,7 @@ func unitWind(unit int, lang string) string {
if !ok {
translation = localizedWind["en"]
}
return translation[unit]
}
@ -308,6 +309,7 @@ func unitVis(unit bool, lang string) string {
if !ok {
translation = localizedVis["en"]
}
return translation[unit]
}
@ -316,5 +318,6 @@ func unitRain(unit bool, lang string) string {
if !ok {
translation = localizedRain["en"]
}
return translation[unit]
}

View file

@ -49,8 +49,10 @@ func printDay(w weather) (ret []string) {
// dateFmt := "┤ " + d.Format("Mon 02. Jan") + " ├"
if val, ok := locale[config.Lang]; ok {
lctime.SetLocale(val)
} else {
lctime.SetLocale("en_US")
}
dateName := ""