From 80bcb32d4c83d18c7996c053834616e0159442c6 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 8 Dec 2023 09:54:35 -0500 Subject: [PATCH] added upc length limiters and fixed 10 digit bug --- main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.go b/main.go index cb1f0e0..cce1d60 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,19 @@ func main() { evenNumber := 0 var remainder int + if upcLength < 10 { + gtins = append(gtins, "Cannot process upcs less than 10 digits") + continue + } + + if upcLength == 10 { + upc = "0" + upc + } + + if upcLength > 13 { + gtins = append(gtins, "GTINs longer than 14 digits are not valid") + } + for i, num := range upc { if i%2 == 0 { oddString, err := strconv.Atoi(string(num))