From 33727db8bee991115906d3408145d5e0806a2455 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Sat, 26 Aug 2023 21:47:47 +0200 Subject: feat: Add initial template renderer for markdown --- parser.go | 85 --------------------------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 parser.go (limited to 'parser.go') diff --git a/parser.go b/parser.go deleted file mode 100644 index 998df91..0000000 --- a/parser.go +++ /dev/null @@ -1,85 +0,0 @@ -package main - -import ( - "strconv" - "strings" - "time" -) - -type ( - // https://wiki.alpinelinux.org/wiki/Apk_spec - Entry struct { - Checksum string // C - Name string // P - Architecture *string // A - PackageSize int // S - InstalledSize *int // I - Description string // T - Url string // U - License string // L - Origin *string // o - Maintainer *string // m - BuildTime *time.Time // t - Commit *string // c - ProviderPriority *int // k - Dependencies []string // D - Provides []string // p - InstallIf []string // i - } -) - -func ptr[T any](v T) *T { - return &v -} - -func split(line string) (string, string) { - parts := strings.SplitN(line, ":", 2) - return parts[0], parts[1] -} - -func toInt(v string) int { - i, _ := strconv.Atoi(v) - return i -} - -func Parse(lines []string) *Entry { - entry := &Entry{} - for _, line := range lines { - r, c := split(line) - switch r { - case "C": - entry.Checksum = c - case "P": - entry.Name = c - case "A": - entry.Architecture = &c - case "S": - entry.PackageSize = toInt(c) - case "I": - entry.InstalledSize = ptr(toInt(c)) - case "T": - entry.Description = c - case "U": - entry.Url = c - case "L": - entry.License = c - case "o": - entry.Origin = &c - case "m": - entry.Maintainer = &c - case "t": - entry.BuildTime = ptr(time.Unix(int64(toInt(c)), 0)) - case "c": - entry.Commit = &c - case "k": - entry.ProviderPriority = ptr(toInt(c)) - case "D": - entry.Dependencies = strings.Split(c, " ") - case "p": - entry.Dependencies = strings.Split(c, " ") - case "i": - entry.Dependencies = strings.Split(c, " ") - } - } - return entry -} -- cgit v1.2.3