Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="a1cacbb5-9844-4dc7-b65f-6d907e69152b" name="Changes" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Go File" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="GOROOT" url="file://$PROJECT_DIR$/../../../../Program Files/Go" />
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 4
|
||||
}</component>
|
||||
<component name="ProjectId" id="2qhC8dgRmsv8EUWhDOwVvGgjdNh" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"DefaultGoTemplateProperty": "Go File",
|
||||
"Go 构建.go build admincenter.executor": "Debug",
|
||||
"Go 构建.go build usercenter.executor": "Debug",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||
"go.import.settings.migrated": "true",
|
||||
"go.sdk.automatically.set": "true",
|
||||
"last_opened_file_path": "D:/workspace/e2023/go_code/center/common/utils",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"settings.editor.selected.configurable": "preferences.keymap"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="D:\workspace\e2023\go_code\center\common\utils" />
|
||||
<recent name="D:\workspace\e2023\go_code\center\common" />
|
||||
<recent name="D:\workspace\e2023\go_code\center\common\connection" />
|
||||
<recent name="D:\workspace\e2023\center\common" />
|
||||
</key>
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="D:\workspace\e2023\center\common" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager" selected="Go 构建.go build admincenter">
|
||||
<configuration name="go build admincenter" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
||||
<module name="center" />
|
||||
<working_directory value="$PROJECT_DIR$/admincenter" />
|
||||
<kind value="PACKAGE" />
|
||||
<package value="admincenter" />
|
||||
<directory value="$PROJECT_DIR$" />
|
||||
<filePath value="$PROJECT_DIR$/admincenter/main.go" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="go build usercenter" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
||||
<module name="center" />
|
||||
<working_directory value="$PROJECT_DIR$/admincenter" />
|
||||
<kind value="PACKAGE" />
|
||||
<package value="usercenter" />
|
||||
<directory value="$PROJECT_DIR$" />
|
||||
<filePath value="$PROJECT_DIR$/admincenter/main.go" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Go 构建.go build admincenter" />
|
||||
<item itemvalue="Go 构建.go build usercenter" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
<option value="bundled-gosdk-5df93f7ad4aa-df9ad98b711f-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-242.22855.85" />
|
||||
<option value="bundled-js-predefined-d6986cc7102b-5c90d61e3bab-JavaScript-GO-242.22855.85" />
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="VgoProject">
|
||||
<settings-migrated>true</settings-migrated>
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
<breakpoints>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/common/configs/init.go</url>
|
||||
<line>34</line>
|
||||
<option name="timeStamp" value="3" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/common/httpServer/reflect.go</url>
|
||||
<line>362</line>
|
||||
<option name="timeStamp" value="28" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
</breakpoint-manager>
|
||||
<watches-manager>
|
||||
<configuration name="GoApplicationRunConfiguration">
|
||||
<watch expression="inTypeItem.Kind()" />
|
||||
</configuration>
|
||||
</watches-manager>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,175 @@
|
||||
package managecenterMgr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"Framework/managecenterModel"
|
||||
. "Framework/managecenterModel"
|
||||
"goutil/logUtil"
|
||||
"goutil/webUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
serverMap = make(map[int32]map[int32]*Server, 128)
|
||||
serverDistinctMap = make(map[int32]*Server, 1024)
|
||||
serverHash string
|
||||
)
|
||||
|
||||
// 重新加载服务器
|
||||
func reloadServer(isInit bool) error {
|
||||
//logUtil.DebugLog("开始刷新服务器列表")
|
||||
|
||||
url := getManageCenterUrl("/API/ServerList.ashx")
|
||||
|
||||
// 定义请求参数
|
||||
postDict := make(map[string]string)
|
||||
postDict["GroupType"] = "Mix"
|
||||
postDict["HashValue"] = serverHash
|
||||
|
||||
//请求url,请求头
|
||||
header := webUtil.GetFormHeader()
|
||||
transport := webUtil.NewTransport()
|
||||
transport.DisableKeepAlives = true
|
||||
transport = webUtil.GetTimeoutTransport(transport, 30)
|
||||
|
||||
statusCode, returnBytes, err := webUtil.PostMapData(url, postDict, header, transport)
|
||||
//statusCode, returnBytes, err := webUtil.PostMapData(url, postDict, header, nil)
|
||||
if err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取服务器列表出错,url:%s,错误信息为:%s", url, err))
|
||||
return err
|
||||
}
|
||||
if statusCode != 200 {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取服务器列表出错,url:%s,错误码为:%d", url, statusCode))
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析返回值
|
||||
returnObj := new(ReturnObject)
|
||||
if err = json.Unmarshal(returnBytes, &returnObj); err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取服务器列表出错,反序列化返回值出错,错误信息为:%s, str:%s", err, string(returnBytes)))
|
||||
return err
|
||||
}
|
||||
|
||||
// 判断返回状态是否成功
|
||||
if returnObj.Code != 0 {
|
||||
// 数据没有变化,所以没有获取到新的数据,不能算错误。
|
||||
if returnObj.Code == 47 || returnObj.Message == "DataNotChanged" {
|
||||
//如果本地集合为空,且数据又没变化时,重新初始化一下本地hash值
|
||||
if len(serverMap) == 0 {
|
||||
serverHash = ""
|
||||
}
|
||||
return nil
|
||||
} else {
|
||||
msg := fmt.Sprintf("获取服务器列表出错,返回状态:%d,信息为:%s", returnObj.Code, returnObj.Message)
|
||||
logUtil.ErrorLog(msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// 解析Data
|
||||
tmpServerList := make([]*Server, 0, 1024)
|
||||
if data, ok := returnObj.Data.(string); !ok {
|
||||
msg := "获取服务器列表出错,返回的数据不是string类型"
|
||||
logUtil.ErrorLog(msg)
|
||||
return errors.New(msg)
|
||||
} else {
|
||||
if err = json.Unmarshal([]byte(data), &tmpServerList); err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取服务器列表出错,反序列化数据出错,错误信息为:%s", err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//logUtil.DebugLog(fmt.Sprintf("刷新服务器信息结束,服务器数量:%d", len(tmpServerList)))
|
||||
|
||||
tmpServerMap := make(map[int32]map[int32]*Server, 128)
|
||||
tmpServerDistinctMap := make(map[int32]*Server, 1024)
|
||||
for _, item := range tmpServerList {
|
||||
// 构造tmpServerMap数据
|
||||
if _, ok := tmpServerMap[item.PartnerId]; !ok {
|
||||
tmpServerMap[item.PartnerId] = make(map[int32]*Server, 1024)
|
||||
}
|
||||
tmpServerMap[item.PartnerId][item.Id] = item
|
||||
|
||||
// 构造tmpServerDistinctMap数据
|
||||
tmpServerDistinctMap[item.Id] = item
|
||||
}
|
||||
|
||||
// 赋值给最终的serverMap、serverDistinctMap
|
||||
serverMap = tmpServerMap
|
||||
serverDistinctMap = tmpServerDistinctMap
|
||||
serverHash = returnObj.HashValue
|
||||
|
||||
//通知变更
|
||||
mcDataChangeCallBack(managecenterModel.ServerData, isInit)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 根据服务器组Id获取对应的服务器列表
|
||||
// serverGroupId:服务器组Id
|
||||
// 返回值:
|
||||
// 服务器列表
|
||||
func GetServerListByGroupId(serverGroupId int32) (serverList []*Server) {
|
||||
for _, subServerMap := range serverMap {
|
||||
for _, item := range subServerMap {
|
||||
if item.GroupId == serverGroupId {
|
||||
serverList = append(serverList, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 根据合作商Id获取对应的服务器列表
|
||||
// partnerId:合作商Id
|
||||
// 返回值:
|
||||
// 服务器列表
|
||||
func GetServerListByPartnerId(partnerId int32) (serverList []*Server) {
|
||||
for _, item := range serverMap[partnerId] {
|
||||
serverList = append(serverList, item)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 根据合作商对象、服务器Id获取服务器对象
|
||||
// partnerObj:合作商对象
|
||||
// serverId:服务器Id
|
||||
// 返回值:
|
||||
// 服务器对象
|
||||
// 是否存在
|
||||
func GetServer(partnerObj *Partner, serverId int32) (serverObj *Server, exist bool) {
|
||||
if subServerMap, exist1 := serverMap[partnerObj.Id]; exist1 {
|
||||
serverObj, exist = subServerMap[serverId]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 根据合作商Id、服务器Id获取服务器对象
|
||||
// partnerId:合作商Id
|
||||
// serverId:服务器Id
|
||||
// 返回值:
|
||||
// 服务器对象
|
||||
// 是否存在
|
||||
func GetServerItem(partnerId, serverId int32) (serverObj *Server, exist bool) {
|
||||
if subServerMap, exist1 := serverMap[partnerId]; exist1 {
|
||||
serverObj, exist = subServerMap[serverId]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 获取不重复的服务器Id列表
|
||||
// 返回值:
|
||||
// 不重复的服务器Id列表
|
||||
func GetDistinctServerIdList() (distinctServerIdList []int32) {
|
||||
for _, item := range serverDistinctMap {
|
||||
distinctServerIdList = append(distinctServerIdList, item.Id)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package monitorMgr
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDuplicate(t *testing.T) {
|
||||
SetParam("20.255.0.7", "Test", 5)
|
||||
|
||||
content := "content"
|
||||
|
||||
if isDuplicate(content) == true {
|
||||
t.Errorf("%s不应该重复却重复了", content)
|
||||
}
|
||||
addToMap(content)
|
||||
if isDuplicate(content) == false {
|
||||
t.Errorf("%s应该重复却没有重复", content)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package webServer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"goutil/logUtil"
|
||||
)
|
||||
|
||||
// Https服务器对象
|
||||
type HttpsServer struct {
|
||||
addr string
|
||||
certFileName string
|
||||
keyFileName string
|
||||
IWebServer
|
||||
server http.Server
|
||||
}
|
||||
|
||||
func (this *HttpsServer) SetAddr(addr string) {
|
||||
this.addr = addr
|
||||
this.server.Addr = addr
|
||||
}
|
||||
|
||||
// 启动HttpsServer
|
||||
func (this *HttpsServer) Start(wg *sync.WaitGroup) {
|
||||
defer func() {
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
// 开启监听
|
||||
msg := fmt.Sprintf("http server begins to listen on: %s...", this.addr)
|
||||
fmt.Println(msg)
|
||||
logUtil.InfoLog(msg)
|
||||
|
||||
if err := this.server.ListenAndServeTLS(this.certFileName, this.keyFileName); err != nil {
|
||||
panic(fmt.Sprintf("https server ListenAndServeTLS Error:%v", err))
|
||||
}
|
||||
}
|
||||
|
||||
// 创建新的HttpsServer
|
||||
// isCheckIP:该属性已丢弃,可以任意赋值
|
||||
func NewHttpsServer(addr, certFileName, keyFileName string, isCheckIP bool) *HttpsServer {
|
||||
webServerObj := NewWebServer(isCheckIP)
|
||||
|
||||
return &HttpsServer{
|
||||
addr: addr,
|
||||
certFileName: certFileName,
|
||||
keyFileName: keyFileName,
|
||||
IWebServer: webServerObj,
|
||||
server: http.Server{
|
||||
Addr: addr,
|
||||
Handler: webServerObj,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 创建新的HttpsServer
|
||||
func NewHttpsServer2(addr, certFileName, keyFileName string, webServerObj IWebServer) *HttpsServer {
|
||||
return &HttpsServer{
|
||||
addr: addr,
|
||||
certFileName: certFileName,
|
||||
keyFileName: keyFileName,
|
||||
IWebServer: webServerObj,
|
||||
server: http.Server{
|
||||
Addr: addr,
|
||||
Handler: webServerObj,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package deviceUtil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConvertMacToStarndardFormat(t *testing.T) {
|
||||
mac := ""
|
||||
expected := ""
|
||||
got := ConvertMacToStandardFormat(mac)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
mac = "00:00:00:00:00:00"
|
||||
expected = ""
|
||||
got = ConvertMacToStandardFormat(mac)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
mac = "02:00:00:00:00:00"
|
||||
expected = ""
|
||||
got = ConvertMacToStandardFormat(mac)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
mac = "02:00:00:00:00"
|
||||
expected = ""
|
||||
got = ConvertMacToStandardFormat(mac)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
mac = "020000000020"
|
||||
expected = "02:00:00:00:00:20"
|
||||
got = ConvertMacToStandardFormat(mac)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
mac = "02:00:00:00:00:20"
|
||||
expected = "02:00:00:00:00:20"
|
||||
got = ConvertMacToStandardFormat(mac)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertIdfaToStandardFormat(t *testing.T) {
|
||||
idfa := ""
|
||||
expected := ""
|
||||
got := ConvertIdfaToStandardFormat(idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
idfa = "00000000-0000-0000-0000-000000000000"
|
||||
expected = ""
|
||||
got = ConvertIdfaToStandardFormat(idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
idfa = "00000000-0000-0000-0000-000000000000-123"
|
||||
expected = "00000000-0000-0000-0000-000000000000-123"
|
||||
got = ConvertIdfaToStandardFormat(idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
idfa = "00000000-1234-5678-0000-000000000000"
|
||||
expected = "00000000-1234-5678-0000-000000000000"
|
||||
got = ConvertIdfaToStandardFormat(idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
idfa = "00000000123456780000000000000000"
|
||||
expected = "00000000-1234-5678-0000-000000000000"
|
||||
got = ConvertIdfaToStandardFormat(idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIdentifier(t *testing.T) {
|
||||
mac := ""
|
||||
idfa := ""
|
||||
expected := ""
|
||||
got := GetIdentifier(mac, idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
mac = "00:00:00:00:00:00"
|
||||
expected = ""
|
||||
got = GetIdentifier(mac, idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
mac = "02:00:00:00:00:00"
|
||||
expected = ""
|
||||
got = GetIdentifier(mac, idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
mac = "020000000020"
|
||||
expected = "02:00:00:00:00:20"
|
||||
got = GetIdentifier(mac, idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
mac = "02:00:00:00:00:20"
|
||||
expected = "02:00:00:00:00:20"
|
||||
got = GetIdentifier(mac, idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
|
||||
idfa = "00000000123456780000000000000000"
|
||||
expected = "00000000-1234-5678-0000-000000000000"
|
||||
got = GetIdentifier(mac, idfa)
|
||||
if got != expected {
|
||||
t.Errorf("Expected: %s, but got:%s", expected, got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user