-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
103 lines (90 loc) · 2.71 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
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
103
package main
import (
"encoding/json"
"flag"
"os"
"errors"
"fmt"
"runtime"
"path"
"io/ioutil"
// "github.com/fatih/structs"
"github.com/barakmich/glog"
"github.com/jnuthong/item_search/logic"
"github.com/jnuthong/item_search/utils"
// "github.com/jnuthong/item_search/db/mongo"
"github.com/jnuthong/item_search/utils/log"
"github.com/jnuthong/item_search/conf"
)
var (
config = flag.String("config", "/home/users/hongjianbin/.jumbo/lib/go/site/src/github.com/jnuthong/item_search/" + "conf.go", "config file path")
inputFile = flag.String("inputFile", "", "file to load, the data format in the file should following the FILELOAD.README file")
logDir = flag.String("logDir", "", "log file directory")
_, file_name, _, _ = runtime.Caller(0)
dir = path.Dir(file_name)
)
type Configuration struct {
DefaultDBName string
DefaultMongIndexKey string
DefaultCollection string
User string
Address string
Port string
Password string
Index []map[string]interface{}
Other string
}
func LoadConfigurationFile(path string) (*Configuration, error) {
// fmt.Println(path)
// file, err := os.Open(path)
file, e := ioutil.ReadFile(path)
if e != nil{
info := utils.CurrentCallerInfo()
conf := new(Configuration)
return conf, errors.New("[error] Couldnt Load Configuration File " + info)
}
conf := new(Configuration)
err := json.Unmarshal(file, &conf)
if err != nil{
info := utils.CurrentCallerInfo()
glog.Fatalln(err)
return conf, errors.New("[error] Couldnt Load Configuration Json " + info)
}
return conf, nil
}
func main(){
flag.Parse()
/* TODO should setting up the default configuration file
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil{
glog.Fatalln(err)
}
*/
var config_path string // config file path
if *config != ""{
config_path = *config
}
conf, err := conf.LoadConfigurationFile(config_path)
// x := structs.New(conf).Map()
if err != nil{
fmt.Println(err)
os.Exit(0)
}
if *inputFile == ""{
fmt.Println("[error] Expect Parameter --inputFile been set")
os.Exit(-1)
}
// TODO should consider another way to config the index list
mongodb_path := "mongodb://" + conf.User + ":" + conf.Password + "@" + conf.Address + ":" + conf.Port + "/" + conf.DefaultDBName
log.Log("info", "[info] Connect Mongo Address: " + mongodb_path)
// db_instance, err := mongo.CreateMongoDBCollection(mongodb_path, x)
// fmt.Println(db_instance)
// c := db_instance.GetCollection()
fmt.Println("InputFile - " + *inputFile)
// err = logic.InsertDocWithFile(*inputFile, "", c)
// err = logic.MultiChan_InsertDocWithFile(*inputFile, dir + "/data/output", c)
err = logic.MultiClient_InsertDocWithFile(*inputFile, dir + "/data/output", *conf)
if err != nil {
fmt.Println(err)
}
}