platform: modularize api/gui, add docs-tests-web foundation, and refresh root config

This commit is contained in:
beckline
2026-03-26 22:40:54 +03:00
parent 0e2d7f61ea
commit 6a56d734c2
562 changed files with 70151 additions and 16423 deletions

View File

@@ -0,0 +1,68 @@
package eventsbus
import (
"sync"
"time"
)
type Event struct {
ID int64
Kind string
Ts string
Data any
}
type Bus struct {
mu sync.Mutex
cond *sync.Cond
buf []Event
cap int
next int64
}
func New(capacity int) *Bus {
if capacity < 16 {
capacity = 16
}
b := &Bus{
cap: capacity,
buf: make([]Event, 0, capacity),
}
b.cond = sync.NewCond(&b.mu)
return b
}
func (b *Bus) Push(kind string, data any) Event {
b.mu.Lock()
defer b.mu.Unlock()
b.next++
evt := Event{
ID: b.next,
Kind: kind,
Ts: time.Now().UTC().Format(time.RFC3339Nano),
Data: data,
}
if len(b.buf) >= b.cap {
b.buf = b.buf[1:]
}
b.buf = append(b.buf, evt)
b.cond.Broadcast()
return evt
}
func (b *Bus) Since(id int64) []Event {
b.mu.Lock()
defer b.mu.Unlock()
if len(b.buf) == 0 {
return nil
}
out := make([]Event, 0, len(b.buf))
for _, ev := range b.buf {
if ev.ID > id {
out = append(out, ev)
}
}
return out
}