-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
157 lines (148 loc) · 3.92 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
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
package main
import (
"fmt"
"net/http"
"os"
"github.com/jameschz/go-base/lib/config"
"github.com/jameschz/go-base/lib/gutil"
// -- example code start
examplegcacheclient "github.com/jameschz/go-base/lib/example/gcacheclient"
examplegdoclient "github.com/jameschz/go-base/lib/example/gdoclient"
examplegetcdclient "github.com/jameschz/go-base/lib/example/getcdclient"
examplegmqclient "github.com/jameschz/go-base/lib/example/gmqclient"
examplehttpserver "github.com/jameschz/go-base/lib/example/httpserver"
examplesocketclient "github.com/jameschz/go-base/lib/example/socketclient"
examplesocketserver "github.com/jameschz/go-base/lib/example/socketserver"
"github.com/jameschz/go-base/lib/logger"
// -- example code end
)
func help() {
fmt.Println("============================================")
fmt.Println("> rootpath", gutil.GetRootPath())
fmt.Println("============================================")
// -- example code start
fmt.Println("> http_server : example http server")
fmt.Println("> so_server : example socket server")
fmt.Println("> so_client : example socket client")
fmt.Println("> gdo_query : example gdo query test")
fmt.Println("> gdo_insert : example gdo insert test")
fmt.Println("> gdo_update : example gdo update test")
fmt.Println("> gdo_delete : example gdo delete test")
fmt.Println("> gdo_query_s : example gdo shard query test")
fmt.Println("> gdo_insert_s : example gdo shard insert test")
fmt.Println("> gdo_update_s : example gdo shard update test")
fmt.Println("> gdo_delete_s : example gdo shard delete test")
fmt.Println("> gdo_tx_basic : example gdo transaction test")
fmt.Println("> gcache_all : example gcache all tests")
fmt.Println("> gmq_pub : example gmq publish test")
fmt.Println("> gmq_sub : example gmq comsume test")
fmt.Println("> etcd_ka : example etcd keepalive test")
fmt.Println("> etcd_sync : example etcd sync trans test")
// -- example code end
fmt.Println("============================================")
os.Exit(0)
}
var (
_serverHTTPAddr string
_serverSocketAddr string
)
func init() {
// init config
_serverHTTPAddr = config.Load("config").GetString("server.http.addr")
_serverSocketAddr = config.Load("config").GetString("server.socket.addr")
}
func main() {
// get args
args := os.Args
if len(args) < 2 || args == nil {
help()
}
// main logic
action := args[1]
switch action {
// -- example code start
case "http_server":
{
fmt.Println("> base http server")
fmt.Println("> listening on", _serverHTTPAddr, "...")
http.HandleFunc("/", examplehttpserver.HTTPIndex)
http.HandleFunc("/hello", examplehttpserver.HTTPHello)
err := http.ListenAndServe(_serverHTTPAddr, nil)
if err != nil {
logger.Error("base server err:", err)
}
}
case "so_server":
{
fmt.Println("> base socket server")
fmt.Println("> bind on " + _serverSocketAddr)
examplesocketserver.Server(_serverSocketAddr)
}
case "so_client":
{
examplesocketclient.Client(_serverSocketAddr)
}
case "gdo_query":
{
examplegdoclient.MysqlQueryBasic()
}
case "gdo_insert":
{
examplegdoclient.MysqlInsertBasic()
}
case "gdo_update":
{
examplegdoclient.MysqlUpdateBasic()
}
case "gdo_delete":
{
examplegdoclient.MysqlDeleteBasic()
}
case "gdo_query_s":
{
examplegdoclient.MysqlQueryShard()
}
case "gdo_insert_s":
{
examplegdoclient.MysqlInsertShard()
}
case "gdo_update_s":
{
examplegdoclient.MysqlUpdateShard()
}
case "gdo_delete_s":
{
examplegdoclient.MysqlDeleteShard()
}
case "gdo_tx_basic":
{
examplegdoclient.MysqlTxBasic()
}
case "gcache_all":
{
examplegcacheclient.TestDriver()
examplegcacheclient.TestRegion()
}
case "gmq_pub":
{
examplegmqclient.RabbitPub()
}
case "gmq_sub":
{
examplegmqclient.RabbitSub()
}
case "etcd_ka":
{
examplegetcdclient.TestKA()
}
case "etcd_sync":
{
examplegetcdclient.TestSync()
}
// -- example code end
default:
{
help()
}
}
}