all repos — honk @ 4bb92097c2b1777cd95482847831e6662d2f27bd

my fork of honk

pointers are easier to understand
Ted Unangst tedu@tedunangst.com
Sat, 30 Dec 2023 18:15:40 -0500
commit

4bb92097c2b1777cd95482847831e6662d2f27bd

parent

821ce27c9785bd2baa1a647378238d55d5a0e612

1 files changed, 8 insertions(+), 8 deletions(-)

jump to
M fun.gofun.go

@@ -163,7 +163,7 @@ }

} if local && h.What != "bonked" { emu, _ := emucache.Get(e) - if emu.ID != "" { + if emu != nil { return fmt.Sprintf(`<img class="emu" title="%s" src="%s">`, emu.Name, emu.ID) } }

@@ -265,7 +265,7 @@ }

} if local { emu, _ := emucache.Get(e) - if emu.ID != "" { + if emu != nil { return fmt.Sprintf(`<img class="emu" title="%s" src="%s">`, emu.Name, emu.ID) } }

@@ -422,7 +422,7 @@ }

var re_emus = regexp.MustCompile(`:[[:alnum:]_-]+:`) -var emucache = gencache.New(gencache.Options[string, Emu]{Fill: func(ename string) (Emu, bool) { +var emucache = gencache.New(gencache.Options[string, *Emu]{Fill: func(ename string) (*Emu, bool) { fname := ename[1 : len(ename)-1] exts := []string{".png", ".gif"} for _, ext := range exts {

@@ -434,18 +434,18 @@ url := fmt.Sprintf("https://%s/emu/%s%s", serverName, fname, ext)

if develMode { url = fmt.Sprintf("/emu/%s%s", fname, ext) } - return Emu{ID: url, Name: ename, Type: "image/" + ext[1:]}, true + return &Emu{ID: url, Name: ename, Type: "image/" + ext[1:]}, true } - return Emu{Name: ename, ID: "", Type: "image/png"}, true + return nil, true }, Duration: 10 * time.Second}) -func herdofemus(noise string) []Emu { +func herdofemus(noise string) []*Emu { m := re_emus.FindAllString(noise, -1) m = oneofakind(m) - var emus []Emu + var emus []*Emu for _, e := range m { emu, _ := emucache.Get(e) - if emu.ID == "" { + if emu == nil { continue } emus = append(emus, emu)