From 9e3a7fddccce3292269ec257aaad7b64088f441e Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 5 Feb 2023 04:41:24 +0400 Subject: [PATCH] Added an Article type. --- pkg/article/article.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pkg/article/article.go diff --git a/pkg/article/article.go b/pkg/article/article.go new file mode 100644 index 0000000..c9c3068 --- /dev/null +++ b/pkg/article/article.go @@ -0,0 +1,32 @@ +package article + +import ( + "bytes" + "errors" + "time" +) + +type Article struct { + Title string + Date time.Time + Description string + Body []byte +} + +func (artcl *Article) ParseMetadata(data []byte) error { + lines := bytes.Split(data, []byte{'\n'}) + if len(lines) != 3 { + return errors.New("metadata file is not complete") + } + + artcl.Title = string(lines[0]) + date, err := time.Parse("02 01 2006", string(lines[1])) + if err != nil { + return err + } + artcl.Date = date + + artcl.Description = string(lines[2]) + + return nil +}