1
0

For Article added a consturctor func New().

This commit is contained in:
Alexander Andreev 2023-09-24 19:02:43 +04:00
parent 1c3f0c7b2c
commit 0695aa46b3
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -15,6 +15,12 @@ type Article struct {
Body []byte Body []byte
} }
func New(body, meta []byte) (article *Article, err error) {
article = &Article{Body: body}
err = article.ParseMetadata(meta)
return
}
func (artcl *Article) ParseMetadata(data []byte) error { func (artcl *Article) ParseMetadata(data []byte) error {
lines := bytes.Split(data, []byte{'\n'}) lines := bytes.Split(data, []byte{'\n'})
if len(lines) != 4 { if len(lines) != 4 {