cpolis/cmd/data/articles.go

42 lines
613 B
Go
Raw Normal View History

package data
2024-03-01 11:30:31 +01:00
import (
"sync"
"time"
"github.com/google/uuid"
)
type Article struct {
Title string
Created time.Time
Desc string
Content string
2024-03-01 11:30:31 +01:00
UUID uuid.UUID
}
type ArticleList struct {
2024-03-01 11:30:31 +01:00
List []Article
sync.Mutex
}
func (l *ArticleList) Add(a Article) {
2024-03-01 11:30:31 +01:00
l.Lock()
l.List = append(l.List, a)
l.Unlock()
}
2024-03-01 11:30:31 +01:00
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
}
}
2024-03-01 11:30:31 +01:00
l.Unlock()
return Article{}, false
}