initial webapp
This commit is contained in:
1 parent
6c989c338c
commit
d32f2b3a66
18 files changed
+1145
-16
No files matched your search
@@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user