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

16
main.go
View File

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

9
rss.go
View File

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