remove some potential nil

This commit is contained in:
Aaron Bieber 2024-04-26 07:13:28 -06:00
parent 36544d813a
commit b188a85a8d
No known key found for this signature in database
2 changed files with 22 additions and 3 deletions

14
main.go
View File

@ -25,7 +25,9 @@ import (
"golang.org/x/crypto/ssh/knownhosts"
)
var commitCache = make(map[string]commit)
var (
commitCache = make(map[string]commit)
)
type commit struct {
hash string
@ -104,7 +106,10 @@ func NewCommit(c string) *commit {
func trim(b []byte) string {
head := bytes.Split(b, []byte("\n"))
if head != nil {
return string(head[0])
}
return ""
}
func (x *xinStatus) aliveCount() float64 {
@ -174,6 +179,9 @@ func (x *xinStatus) updateRepoInfo() error {
if err != nil {
return err
}
if res == nil {
return fmt.Errorf("invalid response")
}
defer res.Body.Close()
@ -447,6 +455,7 @@ func buildCards(stat *xinStatus) fyne.CanvasObject {
}
func main() {
log.SetPrefix("xintray: ")
status := &xinStatus{}
dataPath := path.Clean(path.Join(os.Getenv("HOME"), ".xin.json"))
err := status.config.Load(dataPath)
@ -457,6 +466,9 @@ func main() {
a := app.New()
a.Settings().SetTheme(&xinTheme{})
w := a.NewWindow("xintray")
if w == nil {
log.Fatalln("unable to create window")
}
ctrlQ := &desktop.CustomShortcut{KeyName: fyne.KeyQ, Modifier: fyne.KeyModifierControl}
ctrlW := &desktop.CustomShortcut{KeyName: fyne.KeyW, Modifier: fyne.KeyModifierControl}

9
rss.go
View File

@ -2,6 +2,7 @@ package main
import (
"encoding/xml"
"fmt"
"strings"
"time"
@ -70,9 +71,15 @@ func (f *Feed) LatestHash() (*commit, error) {
}
}
h(doc)
hashParts := strings.Split(f.Entry[0].ID, "/")
if len(hashParts) != 2 {
return nil, fmt.Errorf("invalid hash")
}
hash := hashParts[1]
return &commit{
hash: strings.Split(f.Entry[0].ID, "/")[1],
hash: hash,
// TODO: use x/html to pull out the info?
message: cmitMsg,
//message: html.UnescapeString(f.Entry[0].Content.Text),