Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "time"
  6.  
  7. "gopkg.in/mgo.v2"
  8. "gopkg.in/mgo.v2/bson"
  9. )
  10.  
  11. type Game struct {
  12. Winner string `bson:"winner"`
  13. OfficialGame bool `bson:"official_game"`
  14. Location string `bson:"location"`
  15. StartTime time.Time `bson:"start"`
  16. EndTime time.Time `bson:"end"`
  17. Players []Player `bson:"players"`
  18. }
  19.  
  20. type Player struct {
  21. Name string `bson:"name"`
  22. Decks [2]string `bson:"decks"`
  23. Points uint8 `bson:"points"`
  24. Place uint8 `bson:"place"`
  25. }
  26.  
  27. func NewPlayer(name, firstDeck, secondDeck string, points, place uint8) Player {
  28. return Player{
  29. Name: name,
  30. Decks: [2]string{firstDeck, secondDeck},
  31. Points: points,
  32. Place: place,
  33. }
  34. }
  35.  
  36. func main() {
  37. Host := []string{
  38. "192.168.4.150:27017",
  39. // replica set addrs...
  40. }
  41. const (
  42. Username = "CMdoctor_agg"
  43. Password = "cNewtonapple_AGG"
  44. Database = "order"
  45. Collection = "record"
  46. )
  47. session, err := mgo.DialWithInfo(&mgo.DialInfo{
  48. Addrs: Host,
  49. Username: Username,
  50. Password: Password,
  51. })
  52.  
  53. fmt.Println(err)
  54.  
  55. c := session.DB(Database).C(Collection)
  56. fmt.Println(c)
  57.  
  58. type Result struct {
  59. Type string `bson:"type"`
  60. TempID float64 `bson:"tempID"`
  61. }
  62.  
  63. r := Result{}
  64.  
  65. fmt.Println("Hello")
  66. fmt.Println(c.Find(bson.M{"type": "test"}).One(&r))
  67. fmt.Println(r.TempID)
  68. fmt.Println(r.Type)
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement