Skip to content

Commit

Permalink
整合公共部分入框架
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjinbao committed Dec 17, 2021
1 parent 855a7da commit 293dd90
Show file tree
Hide file tree
Showing 47 changed files with 286 additions and 956 deletions.
2 changes: 0 additions & 2 deletions core/chanrpc/chanrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ func (s *Server) Register(id interface{}, f interface{}) {
panic(fmt.Sprintf("function id %v: already registered", id))
}

//log.Debug("chanrpc", "注册,id=%v,f=%v", id, f)

s.functions[id] = f
}

Expand Down
12 changes: 3 additions & 9 deletions core/conf/apollo/apollo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func SetNetAgent(a network.AgentServer) {
}(timer)
}

//router断开
func CenterDisconnect() {
regSubList = make(map[ConfKey]*ConfValue)
}
Expand Down Expand Up @@ -117,9 +116,8 @@ func ProcessReq(cmd *network.TCPCommand, data []byte) error {
return nil
}

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

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

//发起一次订阅
SendSubscribeReq(nsKey, false)
}

//发送订阅
func SendSubscribeReq(k ConfKey, cancel bool) {
if netAgent == nil {
return
Expand All @@ -163,8 +158,8 @@ func SendSubscribeReq(k ConfKey, cancel bool) {
}

var req config.ApolloCfgReq
req.AppType = proto.Uint32(conf.AppType)
req.AppId = proto.Uint32(conf.AppID)
req.AppType = proto.Uint32(conf.AppInfo.AppType)
req.AppId = proto.Uint32(conf.AppInfo.AppID)
req.SubAppType = proto.Uint32(k.AppType)
req.SubAppId = proto.Uint32(k.AppId)
req.KeyName = proto.String(k.Key)
Expand All @@ -182,7 +177,6 @@ func SendSubscribeReq(k ConfKey, cancel bool) {
netAgent.SendMessage(bm)
}

//注册回调
func RegPublicCB(cb cbNotify) {
if cb == nil {
return
Expand Down
45 changes: 39 additions & 6 deletions core/conf/conf.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,56 @@
package conf

import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
"xlddz/core/util"
)

var (
LenStackBuf = 4096

// console
ConsolePort int = 2021
ConsolePrompt string = "Leaf$:"
ProfilePath string

// skeleton conf
GoLen = 10000
TimerDispatcherLen = 10000
AsynCallLen = 10000
ChanRPCLen = 10000

//服务基础属性
AppInfo BaseInfo
//AppName string
//AppID uint32
//AppType uint32
//ListenOnAddress string
//CenterAddr string
)

type BaseInfo struct {
AppName string
AppID uint32
AppType uint32
ListenOnAddress string
CenterAddr string
)
}

func ParseCmdArgs() {
if AppInfo.AppName != "" {
data, err := ioutil.ReadFile(fmt.Sprintf("conf/%v.json", AppInfo.AppName))
if err == nil {
err = json.Unmarshal(data, &AppInfo)
}
}
if v, ok := util.ParseArgs("/AppID"); ok {
AppInfo.AppID = v
}
if v, ok := util.ParseArgs("/AppType"); ok {
AppInfo.AppType = v
}
if v, ok := util.ParseArgs("/DockerRun"); ok && v == 1 {
addr := strings.Split(AppInfo.CenterAddr, ":")
if len(addr) == 2 {
AppInfo.CenterAddr = "center:" + addr[1]
}
}
}
245 changes: 0 additions & 245 deletions core/console/command.go

This file was deleted.

Loading

0 comments on commit 293dd90

Please sign in to comment.