2023-02-05 04:41:24 +04:00
|
|
|
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 {
|
2023-05-06 05:20:47 +04:00
|
|
|
return errors.New("metadata file is not complete. 3 lines (title, date(DD MM YYYY), descr) should present")
|
2023-02-05 04:41:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|