diff --git a/backend/node.go b/backend/node.go index cdf5c4b..6b82f7e 100644 --- a/backend/node.go +++ b/backend/node.go @@ -23,29 +23,28 @@ import ( ) var ( - dbNodes = []*models.DBNode{} + nodes = []*models.Node{} nodesMap = sync.Map{} //map[ip string]*models.Node ) // LoadNodes ... func LoadNodes() { - dbNodes = data.DAL.SelectAllNodes() - for _, dbNode := range dbNodes { - node := &models.Node{ID: dbNode.ID, Version: dbNode.Version, LastIP: dbNode.LastIP, LastRequestTime: dbNode.LastRequestTime} + nodes = data.DAL.SelectAllNodes() + for _, node := range nodes { nodesMap.Store(node.LastIP, node) } } // GetNodes ... -func GetNodes() ([]*models.DBNode, error) { - return dbNodes, nil +func GetNodes() ([]*models.Node, error) { + return nodes, nil } -// GetDBNodeByID ... -func GetDBNodeByID(id int64) (*models.DBNode, error) { - for _, dbNode := range dbNodes { - if dbNode.ID == id { - return dbNode, nil +// GetNodeByID ... +func GetNodeByID(id int64) (*models.Node, error) { + for _, node := range nodes { + if node.ID == id { + return node, nil } } return nil, errors.New("not found") @@ -59,16 +58,15 @@ func GetNodeByIP(ip string, nodeVersion string) *models.Node { curTime := time.Now().Unix() newID := data.DAL.InsertNode(nodeVersion, ip, curTime) node := &models.Node{ID: newID, Version: nodeVersion, LastIP: ip, LastRequestTime: curTime} - dbNode := &models.DBNode{ID: newID, Version: nodeVersion, LastIP: ip, LastRequestTime: curTime} nodesMap.Store(ip, node) - dbNodes = append(dbNodes, dbNode) + nodes = append(nodes, node) return node } -// GetDBNodeIndex ... -func GetDBNodeIndex(nodeID int64) int { - for i := 0; i < len(dbNodes); i++ { - if dbNodes[i].ID == nodeID { +// GetNodeIndex ... +func GetNodeIndex(nodeID int64) int { + for i := 0; i < len(nodes); i++ { + if nodes[i].ID == nodeID { return i } } @@ -77,15 +75,15 @@ func GetDBNodeIndex(nodeID int64) int { // DeleteNodeByID ... func DeleteNodeByID(id int64) error { - dbNode, err := GetDBNodeByID(id) + dbNode, err := GetNodeByID(id) if err != nil { utils.DebugPrintln("DeleteNodeByID", err) return err } nodesMap.Delete(dbNode.LastIP) err = data.DAL.DeleteNodeByID(id) - i := GetDBNodeIndex(id) - dbNodes = append(dbNodes[:i], dbNodes[i+1:]...) + i := GetNodeIndex(id) + nodes = append(nodes[:i], nodes[i+1:]...) return err } @@ -145,9 +143,9 @@ func IsValidAuthKeyFromReplicaNode(r *http.Request, param map[string]interface{} node.Version = nodeVersion node.LastIP = srcIP node.LastRequestTime = curTime - dbNode, err := GetDBNodeByID(node.ID) + dbNode, err := GetNodeByID(node.ID) if err != nil { - utils.DebugPrintln("IsValidAuthKey GetDBNodeByID", err) + utils.DebugPrintln("IsValidAuthKey GetNodeByID", err) } dbNode.Version = nodeVersion dbNode.LastIP = srcIP diff --git a/data/backend_node.go b/data/backend_node.go index 1ab8796..469c2e6 100644 --- a/data/backend_node.go +++ b/data/backend_node.go @@ -27,17 +27,17 @@ func (dal *MyDAL) DeleteNodeByID(id int64) error { } // SelectAllNodes ... -func (dal *MyDAL) SelectAllNodes() []*models.DBNode { +func (dal *MyDAL) SelectAllNodes() []*models.Node { rows, err := dal.db.Query(sqlSelectAllNodes) if err != nil { utils.DebugPrintln("SelectAllNodes", err) } defer rows.Close() - dbNodes := []*models.DBNode{} + dbNodes := []*models.Node{} for rows.Next() { - dbNode := &models.DBNode{} - _ = rows.Scan(&dbNode.ID, &dbNode.Version, &dbNode.LastIP, &dbNode.LastRequestTime) - dbNodes = append(dbNodes, dbNode) + node := &models.Node{} + _ = rows.Scan(&node.ID, &node.Version, &node.LastIP, &node.LastRequestTime) + dbNodes = append(dbNodes, node) } return dbNodes } diff --git a/gateway/api.go b/gateway/api.go index 8da30e7..d39bc48 100644 --- a/gateway/api.go +++ b/gateway/api.go @@ -103,7 +103,7 @@ func AdminAPIHandlerFunc(w http.ResponseWriter, r *http.Request) { case "get_nodes": obj, err = backend.GetNodes() case "get_node": - obj, err = backend.GetDBNodeByID(apiRequest.ObjectID) + obj, err = backend.GetNodeByID(apiRequest.ObjectID) case "del_node": obj = nil err = backend.DeleteNodeByID(apiRequest.ObjectID) diff --git a/models/node.go b/models/node.go index 5730309..884f50e 100644 --- a/models/node.go +++ b/models/node.go @@ -14,12 +14,14 @@ type Node struct { LastRequestTime int64 `json:"last_req_time"` } +/* type DBNode struct { ID int64 `json:"id,string"` Version string `json:"version"` LastIP string `json:"last_ip"` LastRequestTime int64 `json:"last_req_time"` } +*/ type AuthTime struct { CurTime int64 `json:"cur_time"` diff --git a/static/janusec-admin/assets/images/favicon.ico b/static/janusec-admin/assets/images/favicon.ico index 9fd4575..8ccbb5e 100644 Binary files a/static/janusec-admin/assets/images/favicon.ico and b/static/janusec-admin/assets/images/favicon.ico differ diff --git a/static/janusec-admin/assets/images/logo.png b/static/janusec-admin/assets/images/logo.png index 9fd4575..8ccbb5e 100644 Binary files a/static/janusec-admin/assets/images/logo.png and b/static/janusec-admin/assets/images/logo.png differ diff --git a/static/janusec-admin/favicon.ico b/static/janusec-admin/favicon.ico index 9fd4575..8ccbb5e 100644 Binary files a/static/janusec-admin/favicon.ico and b/static/janusec-admin/favicon.ico differ diff --git a/static/janusec-admin/index.html b/static/janusec-admin/index.html index fb704eb..3678d7c 100644 --- a/static/janusec-admin/index.html +++ b/static/janusec-admin/index.html @@ -12,6 +12,6 @@