mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 10:57:05 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
8
_examples/mvc/vuejs-todo-mvc/src/todo/item.go
Normal file
8
_examples/mvc/vuejs-todo-mvc/src/todo/item.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package todo
|
||||
|
||||
type Item struct {
|
||||
SessionID string `json:"-"`
|
||||
ID int64 `json:"id,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Completed bool `json:"completed"`
|
||||
}
|
||||
46
_examples/mvc/vuejs-todo-mvc/src/todo/service.go
Normal file
46
_examples/mvc/vuejs-todo-mvc/src/todo/service.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package todo
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
Get(owner string) []Item
|
||||
Save(owner string, newItems []Item) error
|
||||
}
|
||||
|
||||
type MemoryService struct {
|
||||
// key = session id, value the list of todo items that this session id has.
|
||||
items map[string][]Item
|
||||
// protected by locker for concurrent access.
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
func NewMemoryService() *MemoryService {
|
||||
return &MemoryService{
|
||||
items: make(map[string][]Item, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *MemoryService) Get(sessionOwner string) []Item {
|
||||
s.mu.RLock()
|
||||
items := s.items[sessionOwner]
|
||||
s.mu.RUnlock()
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
func (s *MemoryService) Save(sessionOwner string, newItems []Item) error {
|
||||
var prevID int64
|
||||
for i := range newItems {
|
||||
if newItems[i].ID == 0 {
|
||||
newItems[i].ID = prevID
|
||||
prevID++
|
||||
}
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
s.items[sessionOwner] = newItems
|
||||
s.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user