-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
102 lines (86 loc) · 3.17 KB
/
main.go
File metadata and controls
102 lines (86 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
// // This program provides a sample application for using MongoDB with
// // the mgo driver.
// package main
// import (
// "log"
// "sync"
// "time"
// "labix.org/v2/mgo"
// )
// const (
// MongoDBHosts = "127.0.0.1"
// AuthDatabase = "crypt"
// AuthUserName = ""
// AuthPassword = ""
// TestDatabase = "crypt"
// )
// // type (
// // processedCurrency struct {
// // Name string `bson:"name"`
// // Base string `bson:"base"`
// // BaseCurrency string `bson:"baseCurrency"`
// // MarketCurrency string `bson:"marketCurrency"`
// // BuyOrders []interface{} `bson:"buyOrders"`
// // SellOrders []interface{} `bson:"sellOrders"`
// // History []interface{} `bson:"history"`
// // Volume float32 `bson:"volume"`
// // BaseVolume float32 `bson:"baseVolume"`
// // Time string `bson:"time"`
// // Price float32 `bson:"price"`
// // }
// // )
// // main is the entry point for the application.
// func main() {
// // We need this object to establish a session to our MongoDB.
// mongoDBDialInfo := &mgo.DialInfo{
// Addrs: []string{MongoDBHosts},
// Timeout: 60 * time.Second,
// Database: AuthDatabase,
// Username: AuthUserName,
// Password: AuthPassword,
// }
// // Create a session which maintains a pool of socket connections
// // to our MongoDB.
// mongoSession, err := mgo.DialWithInfo(mongoDBDialInfo)
// if err != nil {
// log.Fatalf("CreateSession: %s\n", err)
// }
// // Reads may not be entirely up-to-date, but they will always see the
// // history of changes moving forward, the data read will be consistent
// // across sequential queries in the same session, and modifications made
// // within the session will be observed in following queries (read-your-writes).
// // http://godoc.org/labix.org/v2/mgo#Session.SetMode
// mongoSession.SetMode(mgo.Monotonic, true)
// for i := 0; i < 15; i++ {
// // Create a wait group to manage the goroutines.
// var waitGroup sync.WaitGroup
// for result := range bitrex.GetCurrencies() {
// waitGroup.Add(1)
// go RunQuery(result, &waitGroup, mongoSession)
// }
// // Wait for all the queries to complete.
// waitGroup.Wait()
// //close(out)
// log.Println("All Single Queries Completed")
// //time.Sleep(5 * time.Second)
// }
// log.Println("All Queries Completed")
// }
// // RunQuery is a function that is launched as a goroutine to perform
// // the MongoDB work.
// func RunQuery(query bitrex.ProcessedCurrency, waitGroup *sync.WaitGroup, mongoSession *mgo.Session) {
// // Decrement the wait group count so the program knows this
// // has been completed once the goroutine exits.
// defer waitGroup.Done()
// // Request a socket connection from the session to process our query.
// // Close the session when the goroutine exits and put the connection back
// // into the pool.
// sessionCopy := mongoSession.Copy()
// defer sessionCopy.Close()
// // Get a collection to execute the query against.
// collection := sessionCopy.DB(TestDatabase).C("crypt")
// if err := collection.Insert(query); err != nil {
// print(err)
// }
// }