For an article added an ID field used to sort the articles by their appearing, rather by a date.
This commit is contained in:
parent
062139185c
commit
ef316defd9
@ -3,10 +3,12 @@ package article
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Article struct {
|
type Article struct {
|
||||||
|
ID int64
|
||||||
Title string
|
Title string
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Description string
|
Description string
|
||||||
@ -15,18 +17,19 @@ type Article struct {
|
|||||||
|
|
||||||
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) != 3 {
|
if len(lines) != 4 {
|
||||||
return errors.New("metadata file is not complete. 3 lines (title, date(DD MM YYYY), descr) should present")
|
return errors.New("metadata file is not complete. 4 lines (id, title, date(DD MM YYYY), descr) should present")
|
||||||
}
|
}
|
||||||
|
|
||||||
artcl.Title = string(lines[0])
|
artcl.ID, _ = strconv.ParseInt(string(lines[0]), 10, 64)
|
||||||
date, err := time.Parse("02 01 2006", string(lines[1]))
|
artcl.Title = string(lines[1])
|
||||||
|
date, err := time.Parse("02 01 2006", string(lines[2]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
artcl.Date = date
|
artcl.Date = date
|
||||||
|
|
||||||
artcl.Description = string(lines[2])
|
artcl.Description = string(lines[3])
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user