mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 06:40:26 +08:00
API节点自动生成实例代号,用来外界查询多个API节点实例是否为同一个
This commit is contained in:
@@ -161,6 +161,20 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
app.On("instance", func() {
|
||||||
|
var sock = gosock.NewTmpSock(teaconst.ProcessName)
|
||||||
|
reply, err := sock.Send(&gosock.Command{Code: "instance"})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR]" + err.Error())
|
||||||
|
} else {
|
||||||
|
replyJSON, err := json.MarshalIndent(reply.Params, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR]marshal result failed: " + err.Error())
|
||||||
|
} else {
|
||||||
|
fmt.Println(string(replyJSON))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
app.Run(func() {
|
app.Run(func() {
|
||||||
nodes.NewAPINode().Start()
|
nodes.NewAPINode().Start()
|
||||||
|
|||||||
@@ -2,9 +2,18 @@
|
|||||||
|
|
||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
var (
|
import (
|
||||||
IsPlus = false
|
"crypto/sha1"
|
||||||
MaxNodes int32 = 0
|
"fmt"
|
||||||
NodeId int64 = 0
|
"github.com/iwind/TeaGo/rands"
|
||||||
Debug = false
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
IsPlus = false
|
||||||
|
MaxNodes int32 = 0
|
||||||
|
NodeId int64 = 0
|
||||||
|
Debug = false
|
||||||
|
InstanceCode = fmt.Sprintf("%x", sha1.Sum([]byte("INSTANCE"+types.String(time.Now().UnixNano())+"@"+types.String(rands.Int64()))))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -677,6 +677,12 @@ func (this *APINode) listenSock() error {
|
|||||||
Params: map[string]interface{}{"count": 0},
|
Params: map[string]interface{}{"count": 0},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
case "instance":
|
||||||
|
_ = cmd.Reply(&gosock.Command{
|
||||||
|
Params: map[string]interface{}{
|
||||||
|
"code": teaconst.InstanceCode,
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -273,8 +273,9 @@ func (this *APINodeService) FindCurrentAPINode(ctx context.Context, req *pb.Find
|
|||||||
RestHTTPSJSON: nil,
|
RestHTTPSJSON: nil,
|
||||||
AccessAddrsJSON: node.AccessAddrs,
|
AccessAddrsJSON: node.AccessAddrs,
|
||||||
AccessAddrs: accessAddrs,
|
AccessAddrs: accessAddrs,
|
||||||
StatusJSON: nil,
|
StatusJSON: node.Status,
|
||||||
IsPrimary: node.IsPrimary,
|
IsPrimary: node.IsPrimary,
|
||||||
|
InstanceCode: teaconst.InstanceCode,
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user