package web import "sync" // State holds the last rendered report table and row count produced by the // upload handler. The web app is single-user and in-memory, but net/http runs // handlers concurrently, so reads and writes are guarded by an RWMutex. type State struct { mu sync.RWMutex table string rows int } // NewState returns an empty State with no rendered table. func NewState() *State { return &State{} } // Set replaces the stored rendered table string and row count. func (s *State) Set(table string, rows int) { s.mu.Lock() defer s.mu.Unlock() s.table = table s.rows = rows } // Get returns the current rendered table string and row count. The returned // values are zero-valued when no upload has happened yet. func (s *State) Get() (string, int) { s.mu.RLock() defer s.mu.RUnlock() return s.table, s.rows }