todos.go 591 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package types
  2. type Todo struct {
  3. Id int
  4. Title string
  5. IsCompleted bool
  6. }
  7. type TodosIndex map[int]*Todo
  8. func (t *Todo) CheckedStr() string {
  9. if t.IsCompleted {
  10. return "checked"
  11. }
  12. return ""
  13. }
  14. func (t *Todo) CompletedStr() string {
  15. if t.IsCompleted {
  16. return "completed"
  17. }
  18. return ""
  19. }
  20. type TodoListArgs struct {
  21. What string
  22. }
  23. type ReplyOK struct {
  24. Id int
  25. OK bool
  26. }
  27. type ById []Todo
  28. func (l ById) Len() int {
  29. return len(l)
  30. }
  31. func (l ById) Less(i int, j int) bool {
  32. return l[i].Id < l[j].Id
  33. }
  34. func (l ById) Swap(i int, j int) {
  35. l[i], l[j] = l[j], l[i]
  36. }