This repository has been archived on 2025-08-23. You can view files and clone it, but cannot push or open issues or pull requests.
Files
GreenCoast/internal/index/index.go

50 lines
964 B
Go

package index
import (
"sync"
)
// Entry is the index record returned to clients.
// Keep metadata minimal to protect users.
type Entry struct {
Hash string `json:"hash"`
Bytes int64 `json:"bytes"`
StoredAt string `json:"stored_at"` // RFC3339Nano string
Private bool `json:"private"`
CreatorTZ string `json:"creator_tz,omitempty"`
Author string `json:"author,omitempty"` // pseudonymous (thumbprint), optional
}
type Index struct {
mu sync.RWMutex
data map[string]Entry
}
func New() *Index {
return &Index{data: make(map[string]Entry)}
}
func (ix *Index) Put(e Entry) error {
ix.mu.Lock()
ix.data[e.Hash] = e
ix.mu.Unlock()
return nil
}
func (ix *Index) Delete(hash string) error {
ix.mu.Lock()
delete(ix.data, hash)
ix.mu.Unlock()
return nil
}
func (ix *Index) All() []Entry {
ix.mu.RLock()
out := make([]Entry, 0, len(ix.data))
for _, e := range ix.data {
out = append(out, e)
}
ix.mu.RUnlock()
return out
}