forked from ixre/go2o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo2o-serve.go
129 lines (114 loc) · 3.14 KB
/
go2o-serve.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Copyright 2014 @ to2.net.
* name :
* author : jarryliu
* date : 2013-12-16 21:45
* description :
* history :
*/
package main
import (
"flag"
"fmt"
"github.com/ixre/gof"
"github.com/ixre/gof/storage"
"github.com/ixre/gof/web"
"go2o/app"
"go2o/app/cache"
"go2o/app/daemon"
"go2o/app/restapi"
"go2o/core"
"go2o/core/msq"
"go2o/core/service/rsi"
rs "go2o/core/service/thrift/service"
"log"
"os"
"runtime"
"strings"
)
var _ = `
### ### ### ###
# # ## # # ##
# # # # # #
# # # # ## # #
# # # # # # #
### ### ### ###
Go2o is Google Go language binding domain-driven design (DDD) O2O open source implementation. Support Online Store
, Offline stores; multi-channel (businesses), multi-store, merchandise, snapshots, orders, sales, payment, distribution and other functions.
Project by a management center (including platform management center, business background, store background), online store (PC shop,
Handheld shops, micro-channel), the member center, open API in four parts.
Go2o using domain-driven design for business depth abstract, theoretical support in most sectors O2O scenarios.
Through open API, you can seamlessly integrate into legacy systems.
Email: jarrysix#gmail.com
`
func main() {
var (
ch = make(chan bool)
confFile string
port int
apiPort int
kafkaAddr string
debug bool
trace bool
runDaemon bool // 运行daemon
help bool
showVer bool
newApp *core.AppImpl
appFlag = app.FlagWebApp
)
defaultKafkaAddr := os.Getenv("GO2O_KAFKA_ADDR")
if len(defaultKafkaAddr) == 0 {
defaultKafkaAddr = "127.0.0.1:9092"
}
flag.IntVar(&port, "-port", 1427, "thrift service port")
flag.IntVar(&apiPort, "-apiport", 1428, "api service port")
flag.BoolVar(&debug, "debug", false, "enable debug")
flag.BoolVar(&trace, "trace", false, "enable trace")
flag.BoolVar(&help, "help", false, "command usage")
flag.StringVar(&confFile, "conf", "app.conf", "")
flag.StringVar(&kafkaAddr, "kafka", defaultKafkaAddr,
"kafka cluster address, like: 192.168.1.1:9092,192.168.1.2:9092")
flag.BoolVar(&runDaemon, "d", false, "run daemon")
flag.BoolVar(&showVer, "v", false, "print version")
flag.Parse()
if runDaemon {
appFlag = appFlag | app.FlagDaemon
}
appFlag = appFlag | app.FlagRpcServe
if help {
flag.Usage()
return
}
if showVer {
fmt.Println(fmt.Sprintf("go2o version v%s", core.Version))
return
}
log.SetOutput(os.Stdout)
log.SetFlags(log.LstdFlags | log.Ltime | log.Ldate | log.Lshortfile)
runtime.GOMAXPROCS(runtime.NumCPU())
newApp = core.NewApp(confFile)
if debug {
go app.AutoInstall()
}
if !core.Init(newApp, debug, trace) {
os.Exit(1)
}
go core.SignalNotify(ch)
gof.CurrentApp = newApp
cache.Initialize(storage.NewRedisStorage(newApp.Redis()))
web.Initialize(web.Options{
Storage: newApp.Storage(),
XSRFCookie: true,
})
rsi.Init(newApp, appFlag)
// 初始化producer
msq.Configure(msq.KAFKA, strings.Split(kafkaAddr, ","))
// 运行RPC服务
go rs.ListenAndServe(fmt.Sprintf(":%d", port), false)
// 运行REST API
go restapi.Run(newApp, apiPort)
if runDaemon {
go daemon.Run(newApp)
}
<-ch
}