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