Skip to content

Commit 293dd90

Browse files
author
zhangjinbao
committed
整合公共部分入框架
1 parent 855a7da commit 293dd90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+286
-956
lines changed

core/chanrpc/chanrpc.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ func (s *Server) Register(id interface{}, f interface{}) {
7777
panic(fmt.Sprintf("function id %v: already registered", id))
7878
}
7979

80-
//log.Debug("chanrpc", "注册,id=%v,f=%v", id, f)
81-
8280
s.functions[id] = f
8381
}
8482

core/conf/apollo/apollo.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func SetNetAgent(a network.AgentServer) {
6161
}(timer)
6262
}
6363

64-
//router断开
6564
func CenterDisconnect() {
6665
regSubList = make(map[ConfKey]*ConfValue)
6766
}
@@ -117,9 +116,8 @@ func ProcessReq(cmd *network.TCPCommand, data []byte) error {
117116
return nil
118117
}
119118

120-
// 读取配置中心的配置,找不到时,返回空字符串
121119
func GetConfig(key, defaultValue string) string {
122-
nsKey := ConfKey{Key: key, AppType: conf.AppType, AppId: conf.AppID}
120+
nsKey := ConfKey{Key: key, AppType: conf.AppInfo.AppType, AppId: conf.AppInfo.AppID}
123121
mutexConfig.Lock()
124122
defer mutexConfig.Unlock()
125123
if item, ok := configValues[nsKey]; ok {
@@ -128,7 +126,6 @@ func GetConfig(key, defaultValue string) string {
128126
return defaultValue
129127
}
130128

131-
// 读取配置中心的配置,找不到或出错时,返回0
132129
func GetConfigAsInt64(key string, defaultValue int64) int64 {
133130
v, _ := strconv.ParseInt(GetConfig(key, strconv.FormatInt(defaultValue, 10)), 10, 64)
134131
return v
@@ -146,11 +143,9 @@ func RegisterConfig(key string, reqAppType, reqAppId uint32, cb cbNotify) {
146143
mxRegSub.Unlock()
147144
log.Info("Apollo", "注册Apollo订阅,%v", nsKey)
148145

149-
//发起一次订阅
150146
SendSubscribeReq(nsKey, false)
151147
}
152148

153-
//发送订阅
154149
func SendSubscribeReq(k ConfKey, cancel bool) {
155150
if netAgent == nil {
156151
return
@@ -163,8 +158,8 @@ func SendSubscribeReq(k ConfKey, cancel bool) {
163158
}
164159

165160
var req config.ApolloCfgReq
166-
req.AppType = proto.Uint32(conf.AppType)
167-
req.AppId = proto.Uint32(conf.AppID)
161+
req.AppType = proto.Uint32(conf.AppInfo.AppType)
162+
req.AppId = proto.Uint32(conf.AppInfo.AppID)
168163
req.SubAppType = proto.Uint32(k.AppType)
169164
req.SubAppId = proto.Uint32(k.AppId)
170165
req.KeyName = proto.String(k.Key)
@@ -182,7 +177,6 @@ func SendSubscribeReq(k ConfKey, cancel bool) {
182177
netAgent.SendMessage(bm)
183178
}
184179

185-
//注册回调
186180
func RegPublicCB(cb cbNotify) {
187181
if cb == nil {
188182
return

core/conf/conf.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,56 @@
11
package conf
22

3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
"strings"
8+
"xlddz/core/util"
9+
)
10+
311
var (
412
LenStackBuf = 4096
513

6-
// console
7-
ConsolePort int = 2021
8-
ConsolePrompt string = "Leaf$:"
9-
ProfilePath string
10-
1114
// skeleton conf
1215
GoLen = 10000
1316
TimerDispatcherLen = 10000
1417
AsynCallLen = 10000
1518
ChanRPCLen = 10000
1619

1720
//服务基础属性
21+
AppInfo BaseInfo
22+
//AppName string
23+
//AppID uint32
24+
//AppType uint32
25+
//ListenOnAddress string
26+
//CenterAddr string
27+
)
28+
29+
type BaseInfo struct {
1830
AppName string
1931
AppID uint32
2032
AppType uint32
2133
ListenOnAddress string
2234
CenterAddr string
23-
)
35+
}
36+
37+
func ParseCmdArgs() {
38+
if AppInfo.AppName != "" {
39+
data, err := ioutil.ReadFile(fmt.Sprintf("conf/%v.json", AppInfo.AppName))
40+
if err == nil {
41+
err = json.Unmarshal(data, &AppInfo)
42+
}
43+
}
44+
if v, ok := util.ParseArgs("/AppID"); ok {
45+
AppInfo.AppID = v
46+
}
47+
if v, ok := util.ParseArgs("/AppType"); ok {
48+
AppInfo.AppType = v
49+
}
50+
if v, ok := util.ParseArgs("/DockerRun"); ok && v == 1 {
51+
addr := strings.Split(AppInfo.CenterAddr, ":")
52+
if len(addr) == 2 {
53+
AppInfo.CenterAddr = "center:" + addr[1]
54+
}
55+
}
56+
}

core/console/command.go

Lines changed: 0 additions & 245 deletions
This file was deleted.

0 commit comments

Comments
 (0)