Guest User

Untitled

a guest
Jul 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. type Author struct {
  2. ID string `bson:"id"`
  3. Name string `bson:"name"`
  4. Timestamp time.Time
  5. }
  6.  
  7. type Article struct {
  8. ID bson.ObjectId `bson:"_id,omitempty"`
  9. Title string `bson:"title"`
  10. Content string `bson:"content"`
  11. Author Author `bson:"inline"`
  12. Timestamp time.Time
  13. }
  14.  
  15. func (m *mgoArticleRepository) FindAll() ([]*models.Article, error) {
  16. result := make([]*models.Article, 0)
  17. sessionCopy := m.Conn.Copy()
  18. defer sessionCopy.Close()
  19. collection := sessionCopy.DB(DBNAME).C(COLLECTION)
  20. err := collection.Find(nil).All(&result)
  21. return result, err
  22. }
  23.  
  24. [
  25. {
  26. "ID":"5b4f27c187a9e40828422cca",
  27. "Title":"Makan Ayam",
  28. "Content":"Sample values One",
  29. "Author":{
  30. "ID":"",
  31. "Name":"",
  32. "Timestamp":"0001-01-01T00:00:00Z"
  33. },
  34. "Timestamp":"0001-01-01T00:00:00Z"
  35. },
  36. {
  37. "ID":"5b4f27c187a9e40828422ccb",
  38. "Title":"Makan Ikan",
  39. "Content":"Sample values Two",
  40. "Author":{
  41. "ID":"",
  42. "Name":"",
  43. "Timestamp":"0001-01-01T00:00:00Z"
  44. },
  45. "Timestamp":"0001-01-01T00:00:00Z"
  46. },
  47. {
  48. "ID":"5b4f27c187a9e40828422ccc",
  49. "Title":"Makan Sayur",
  50. "Content":"Sample values Three",
  51. "Author":{
  52. "ID":"",
  53. "Name":"",
  54. "Timestamp":"0001-01-01T00:00:00Z"
  55. },
  56. "Timestamp":"0001-01-01T00:00:00Z"
  57. },
  58. {
  59. "ID":"5b4f27c187a9e40828422ccd",
  60. "Title":"Makan Daging",
  61. "Content":"Sample values Four",
  62. "Author":{
  63. "ID":"",
  64. "Name":"",
  65. "Timestamp":"0001-01-01T00:00:00Z"
  66. },
  67. "Timestamp":"0001-01-01T00:00:00Z"
  68. },
  69. {
  70. "ID":"5b4f27c187a9e40828422cce",
  71. "Title":"Makan Indomie",
  72. "Content":"Sample values Five",
  73. "Author":{
  74. "ID":"",
  75. "Name":"",
  76. "Timestamp":"0001-01-01T00:00:00Z"
  77. },
  78. "Timestamp":"0001-01-01T00:00:00Z"
  79. },
  80. {
  81. "ID":"5b4f27c187a9e40828422ccf",
  82. "Title":"Makan Soto",
  83. "Content":"Sample values Six",
  84. "Author":{
  85. "ID":"",
  86. "Name":"",
  87. "Timestamp":"0001-01-01T00:00:00Z"
  88. },
  89. "Timestamp":"0001-01-01T00:00:00Z"
  90. }
  91. ]
  92.  
  93. Author Author `bson:"inline"
  94.  
  95. Author Author `bson:"Author"`
Add Comment
Please, Sign In to add comment