-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (48 loc) · 1.3 KB
/
main.go
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
package main
import (
//"mongorestaurantsample-master/domain"
"fmt"
"os"
"strings"
// "bson"
// dbrepo "github.com/priteshgudge/mongosample/dbrepository"
dbrepo "./dbrepository"
// mongoutils "github.com/priteshgudge/mongosample/utils"
mongoutils "./utils"
)
// importing domain obbject restaurant
//import "mongorestaurantsample-master/domain"
//import "gopkg.in/mgo.v2/bson"
func main() {
//pass mongohost through the environment
mongoSession, _ := mongoutils.RegisterMongoSession(os.Getenv("MONGO_HOST"))
dbname := "restaurant"
repoaccess := dbrepo.NewMongoRepository(mongoSession, dbname)
// fmt.Println(repoaccess)
//Run sample commands
document := os.Args[1]
data := os.Args[2]
s := strings.Split(data, "=")
s[0] = s[0][2:]
var count int
if document == "find" {
if s[0] == "type_of_food" {
result, _ := repoaccess.FindByTypeOfFood(s[1])
fmt.Println(result)
} else if s[0] == "postcode" {
result, _ := repoaccess.FindByTypeOfPostCode(s[1])
fmt.Println(result)
} else {
fmt.Println("Invalid arguments")
}
} else if document == "count" {
if s[0] == "type_of_food" {
count, _ = repoaccess.CountRestaurantByFood(s[1])
fmt.Println("count Restaurant ByFood ", count)
} else {
fmt.Println("Invalid arguments")
}
} else {
fmt.Println("Invalid arguments")
}
}