forked from ixre/go2o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo2o-serve.go
executable file
·173 lines (156 loc) · 4.24 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* 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/web"
"go.etcd.io/etcd/clientv3"
"go2o/app"
"go2o/app/v1/restapi"
"go2o/core"
"go2o/core/msq"
"go2o/core/service"
"go2o/core/service/impl"
"log"
"os"
"strings"
"time"
)
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
etcdEndPoints gof.ArrayFlags
port int
apiPort int
mqAddr string
debug bool
trace bool
runDaemon bool // 运行daemon
help bool
showVer bool
newApp *core.AppImpl
appFlag = app.FlagWebApp
)
defaultMqAddr := os.Getenv("GO2O_NATS_ADDR")
if len(defaultMqAddr) == 0 {
defaultMqAddr = "127.0.0.1:4222"
}
flag.IntVar(&port, "port", 1427, "thrift service port")
flag.IntVar(&apiPort, "apiport", 1428, "api service port")
flag.Var(&etcdEndPoints, "endpoint", "")
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(&mqAddr, "mqs", defaultMqAddr,
"mq cluster address, like: 192.168.1.1:4222,192.168.1.2:4222")
flag.BoolVar(&runDaemon, "d", false, "run daemon")
flag.BoolVar(&showVer, "v", false, "print version")
flag.Parse()
//confFile = "./app_dev.conf"
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)
// 默认的ETCD端点
if len(etcdEndPoints) == 0 {
etcdEndPoints = strings.Split(os.Getenv("GO2O_ETCD_ADDR"), ",")
if len(etcdEndPoints) == 0 || etcdEndPoints[0] == "" {
etcdEndPoints = []string{"http://127.0.0.1:2379"}
}
}
cfg := clientv3.Config{
Endpoints: etcdEndPoints,
DialTimeout: 5 * time.Second,
}
newApp = core.NewApp(confFile, &cfg)
if debug {
go app.AutoInstall()
}
gof.CurrentApp = newApp
if !core.Init(newApp, debug, trace) {
os.Exit(1)
}
go core.SignalNotify(ch, core.AppDispose)
web.Initialize(web.Options{
Storage: newApp.Storage(),
XSRFCookie: true,
})
impl.Init(newApp)
//runGoMicro()
// 初始化producer
_ = msq.Configure(msq.NATS, strings.Split(mqAddr, ","))
// 运行RPC服务
service.ServeRPC(ch, &cfg, port)
service.ConfigureClient(cfg) // initial service client
if runDaemon {
//todo: daemon需重构
//go daemon.Run(newApp)
}
// 运行REST API
go restapi.Run(ch, newApp, apiPort)
<-ch
}
/*
// todo: v3 还是测试版本
func runGoMicro() {
r := consul.NewRegistry(func(options *registry.Options) {
options.Addrs = []string{
"127.0.0.1:8500",
}
})
grpc.NewServer(
server.Name("Greeter"),
server.Registry(NewRegisterV3(r)))
s := service.New(
service.Name("Greeter"),
service.Address(":1081"),
)
//service := micro.NewService(
// micro.Name("Greeter"),
// //micro.Address(":1081"),
// micro.Registry(r),
// )
//service.Init()
s.Handle(new(grpc.TestServiceImpl))
//proto.RegisterGreeterServiceHandler(service,new(grpc.TestServiceImpl))
service.Run()
}
func NewRegisterV3(r registry.Registry) registry2.Registry {
return &RegisterV3{r}
}
*/