From 6a68d439976786b05939d86d6840e410d95ec1ea Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Mon, 16 Sep 2019 16:46:14 -0400 Subject: [PATCH] combine common code --- database.go | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/database.go b/database.go index ca08004..7dcadb7 100644 --- a/database.go +++ b/database.go @@ -90,10 +90,10 @@ func allusers() []login.UserInfo { return users } -func getxonk(userid int64, xid string) *Honk { +func scanxonk(row *sql.Row) *Honk { h := new(Honk) var dt, aud, onts string - row := stmtOneXonk.QueryRow(userid, xid) + err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.Oonker, &h.XID, &h.RID, &dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Convoy, &h.Whofore, &h.Flags, &onts) if err != nil { @@ -111,25 +111,14 @@ func getxonk(userid int64, xid string) *Honk { return h } +func getxonk(userid int64, xid string) *Honk { + row := stmtOneXonk.QueryRow(userid, xid) + return scanxonk(row) +} + func getbonk(userid int64, xid string) *Honk { - h := new(Honk) - var dt, aud, onts string row := stmtOneBonk.QueryRow(userid, xid) - err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.Oonker, &h.XID, &h.RID, - &dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Convoy, &h.Whofore, &h.Flags, &onts) - if err != nil { - if err != sql.ErrNoRows { - log.Printf("error scanning xonk: %s", err) - } - return nil - } - h.Date, _ = time.Parse(dbtimeformat, dt) - h.Audience = strings.Split(aud, " ") - h.Public = !keepitquiet(h.Audience) - if len(onts) > 0 { - h.Onts = strings.Split(onts, " ") - } - return h + return scanxonk(row) } func getpublichonks() []*Honk {