split into packages
This commit is contained in:
parent
2b56832843
commit
c5d41b0965
26 changed files with 328 additions and 449 deletions
43
editor.go
43
editor.go
|
|
@ -1,43 +0,0 @@
|
|||
package main
|
||||
|
||||
import "sync"
|
||||
|
||||
type Editor struct {
|
||||
Username string
|
||||
Time string
|
||||
}
|
||||
|
||||
type EditorStore struct {
|
||||
sync.RWMutex
|
||||
m map[string]*Editor
|
||||
}
|
||||
|
||||
func NewEditorStore() *EditorStore {
|
||||
return &EditorStore{m: make(map[string]*Editor)}
|
||||
}
|
||||
|
||||
func (e *EditorStore) Set(page, username string) *Editor {
|
||||
e.Lock()
|
||||
defer e.Unlock()
|
||||
editor := e.m[page]
|
||||
if editor != nil {
|
||||
return editor
|
||||
}
|
||||
e.m[page] = &Editor{username, now()}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *EditorStore) RemoveEditor(page, username string) {
|
||||
e.Lock()
|
||||
defer e.Unlock()
|
||||
if editor, ok := e.m[page]; ok {
|
||||
if editor.Username == username {
|
||||
delete(e.m, page)
|
||||
}
|
||||
}
|
||||
}
|
||||
func (e *EditorStore) Remove(page string) {
|
||||
e.Lock()
|
||||
defer e.Unlock()
|
||||
delete(e.m, page)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue