/
distribute.go
50 lines (45 loc) · 1.21 KB
/
distribute.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
package main
/**
* @author carlding
* @date : 2015-12-8
*/
import (
"github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/mflag"
"go_distributed_spider/config"
"go_distributed_spider/distributed"
"os"
)
var (
master, help bool
env, conffile string
)
func init() {
logrus.SetOutput(os.Stdout)
logrus.SetLevel(logrus.DebugLevel)
mflag.BoolVar(&master, []string{"m", "-master", "#mt"}, false, "if the master server.")
mflag.BoolVar(&help, []string{"h", "-help", "#hhhhelp"}, false, "show help.")
mflag.StringVar(&env, []string{"e", "-env"}, "test", "which config env to run.")
// mflag.BoolVar(&picture, []string{"i", "-image"}, false, "download the picture that go throuth.")
mflag.StringVar(&conffile, []string{"f", "-config"}, "", "point a config file.default is config/config.json.")
mflag.Parse()
}
func main() {
if help {
mflag.PrintDefaults()
return
}
config, err := config.ReadConfig(conffile, env)
if err != nil {
logrus.Errorln("main", err)
return
}
var distribute distributed.Distributed
if master {
distribute = &distributed.Master{}
} else {
distribute = &distributed.Slave{}
}
distribute.Init(config)
distribute.Done("str")
}