cpolis/cmd/data/articles.go

42 lines
613 B
Go

package data
import (
"sync"
"time"
"github.com/google/uuid"
)
type Article struct {
Title string
Created time.Time
Desc string
Content string
UUID uuid.UUID
}
type ArticleList struct {
List []Article
sync.Mutex
}
func (l *ArticleList) Add(a Article) {
l.Lock()
l.List = append(l.List, a)
l.Unlock()
}
func (l *ArticleList) Release(uuid uuid.UUID) (Article, bool) {
l.Lock()
for i, article := range l.List {
if article.UUID == uuid {
foo := l.List[i]
l.List = append(l.List[:i], l.List[i+1:]...)
l.Unlock()
return foo, true
}
}
l.Unlock()
return Article{}, false
}