From a7c8ff26cafcd9141c06255a99c202fc98f815cf Mon Sep 17 00:00:00 2001 From: Joshua Herring Date: Wed, 27 May 2026 12:52:52 -0400 Subject: [PATCH] move shared utility functions into utils --- dbi/scholarship.go | 9 +++------ dbi/utils.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 dbi/utils.go diff --git a/dbi/scholarship.go b/dbi/scholarship.go index 09d8ea3..cbf91c5 100644 --- a/dbi/scholarship.go +++ b/dbi/scholarship.go @@ -4,10 +4,7 @@ import ( "context" "database/sql" "fmt" - "strings" - "time" - "github.com/google/uuid" ) type Scholarship struct { @@ -22,9 +19,9 @@ type Scholarship struct { func CreateScholarship(conn *sql.Conn, s *Scholarship) error { if s.UID == "" { - s.UID = strings.ReplaceAll(uuid.New().String(), "-", "") + s.UID = GenUUID() } - now := time.Now().Format("2006-01-02 15:04:05") + now := GetNow() s.Created = now s.Modified = now _, err := conn.ExecContext(context.Background(), @@ -50,7 +47,7 @@ func GetScholarship(conn *sql.Conn, uid string) (Scholarship, error) { } func UpdateScholarship(conn *sql.Conn, s *Scholarship) error { - s.Modified = time.Now().Format("2006-01-02 15:04:05") + s.Modified = GetNow() _, err := conn.ExecContext(context.Background(), `UPDATE scholarship SET Citation = ?, Hyperlink = ?, Status = ?, Modified = ?, Username = ? WHERE UID = ?`, diff --git a/dbi/utils.go b/dbi/utils.go new file mode 100644 index 0000000..66c9250 --- /dev/null +++ b/dbi/utils.go @@ -0,0 +1,18 @@ +package dbi + +import ( + "strings" + "time" + + "github.com/google/uuid" +) + +const TMFormat = "2006-01-02 15:04:05" + +func GetNow() string { + return time.Now().Format(TMFormat) +} + +func GenUUID() string { + return strings.ReplaceAll(uuid.New().String(), "-", "") +}