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

View file

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

View file

@ -131,6 +131,7 @@ func formatTemp(c cond) string {
if explicitPlus { 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)
} }
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 t := c.TempC
@ -158,6 +159,7 @@ func formatTemp(c cond) string {
if explicitPlus1 { if explicitPlus1 {
explicitPlus2 = false explicitPlus2 = false
} }
return pad( return pad(
fmt.Sprintf("%s(%s) °%s", fmt.Sprintf("%s(%s) °%s",
color(t, explicitPlus1), color(t, explicitPlus1),
@ -188,6 +190,7 @@ func formatWind(c cond) string {
spd = (spd * 1000) / 1609 spd = (spd * 1000) / 1609
} }
} }
return spd return spd
} }
color := func(spd int) string { color := func(spd int) string {
@ -230,6 +233,7 @@ func formatWind(c cond) string {
} }
} }
hyphen := " - " hyphen := " - "
// if (config.Lang == "sl") { // if (config.Lang == "sl") {
// hyphen = "-" // hyphen = "-"
@ -241,6 +245,7 @@ func formatWind(c cond) string {
if windInRightUnits(c.WindGustKmph) > windInRightUnits(c.WindspeedKmph) { 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%s %s", windDir[c.Winddir16Point], cWindspeedKmph, hyphen, cWindGustKmph, unitWindString), 15)
} }
return pad(fmt.Sprintf("%s %s %s", windDir[c.Winddir16Point], cWindspeedKmph, 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 { if config.Imperial {
c.VisibleDistKM = (c.VisibleDistKM * 621) / 1000 c.VisibleDistKM = (c.VisibleDistKM * 621) / 1000
} }
return pad(fmt.Sprintf("%d %s", c.VisibleDistKM, unitVis(config.Imperial, config.Lang)), 15) return pad(fmt.Sprintf("%d %s", c.VisibleDistKM, unitVis(config.Imperial, config.Lang)), 15)
} }
@ -262,7 +268,9 @@ func formatRain(c cond) string {
rainUnit, rainUnit,
unitRain(config.Imperial, config.Lang), unitRain(config.Imperial, config.Lang),
c.ChanceOfRain), 15) c.ChanceOfRain), 15)
} }
return pad(fmt.Sprintf("%.1f %s", rainUnit, unitRain(config.Imperial, config.Lang)), 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])) 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 { } 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))) 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 return
} }
@ -348,7 +358,9 @@ func justifyCenter(s string, width int) string {
s = " " + s s = " " + s
appendSide = 1 appendSide = 1
} }
} }
return s return s
} }
@ -356,7 +368,9 @@ func reverse(s string) string {
r := []rune(s) r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 { 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] r[i], r[j] = r[j], r[i]
} }
return string(r) return string(r)
} }
@ -379,6 +393,8 @@ func pad(s string, mustLen int) (ret string) {
} else { } else {
ret = fmt.Sprintf("%s%s%s", toks[0], esc, pad(toks[1], mustLen-tokLen)) ret = fmt.Sprintf("%s%s%s", toks[0], esc, pad(toks[1], mustLen-tokLen))
} }
} }
return return
} }

View file

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

View file

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