♻️ Use defined errors

This commit is contained in:
Dan Jones 2024-01-28 12:41:55 -06:00
commit 2d68691408
5 changed files with 34 additions and 20 deletions

View file

@ -29,12 +29,12 @@ func (e Entry) getFieldMarshalChan() chan metaRes {
// @todo figure out a way to handle json field
for i := 0; i < size; i++ {
wg.Add(1)
go func(i int) {
go func(m Meta) {
defer wg.Done()
o, er := e.Fields[i].MarshalText()
o, er := m.MarshalText()
ch <- metaRes{o, er}
}(i)
}(e.Fields[i])
}
go func() {
@ -47,10 +47,10 @@ func (e Entry) getFieldMarshalChan() chan metaRes {
func (e Entry) MarshalText() ([]byte, error) {
e.Title = strings.TrimSpace(e.Title)
if e.Title == "" {
return []byte{}, errors.New("Empty title")
return []byte{}, ErrorMissingTitle
}
if e.Date == (time.Time{}) {
return []byte{}, errors.New("Empty date")
return []byte{}, ErrorMissingDate
}
ch := e.getFieldMarshalChan()
buff := &bytes.Buffer{}