diff --git a/Go/source/main.go b/Go/source/main.go index aed654c..901aa25 100644 --- a/Go/source/main.go +++ b/Go/source/main.go @@ -23,7 +23,7 @@ func NextId() uint64 { // 注册一个新的WorkerId //export RegisterWorkerId func RegisterWorkerId(ip *C.char, port int, password *C.char, maxWorkerId int) int { - return regworkerid.RegisterWorkerId(C.GoString(ip), port, C.GoString(password), maxWorkerId) + return int(regworkerid.RegisterWorkerId(C.GoString(ip), port, C.GoString(password), maxWorkerId)) } // 注销WorkerId @@ -32,9 +32,9 @@ func UnRegisterWorkerId() { regworkerid.UnRegisterWorkerId() } -// 检查本地WorkerId是否有效 +// 检查本地WorkerId是否有效(0-有效,其它-无效) //export ValidateLocalWorkerId -func ValidateLocalWorkerId(workerId int) bool { +func ValidateLocalWorkerId(workerId int) int { return regworkerid.ValidateLocalWorkerId(workerId) } diff --git a/Go/source/regworkerid/reghelper.go b/Go/source/regworkerid/reghelper.go index 6c90d85..09485dc 100644 --- a/Go/source/regworkerid/reghelper.go +++ b/Go/source/regworkerid/reghelper.go @@ -26,8 +26,12 @@ const _WorkerIdValueKeyPrefix string = "IdGen:WorkerId:Value:" // redis 中的ke const _WorkerIdFlag = "Y" // IdGen:WorkerId:Value:xx 的值(将来可用 _token 替代) const _Log = false // 是否输出日志 -func ValidateLocalWorkerId(workerId int) bool { - return workerId == _usingWorkerId +func ValidateLocalWorkerId(workerId int) int { + if workerId == _usingWorkerId { + return 0 + } else { + return -1 + } } func UnRegisterWorkerId() { diff --git a/Go/source/target/yitidgengo.dll b/Go/source/target/yitidgengo.dll index d259d2b..d9468a4 100644 Binary files a/Go/source/target/yitidgengo.dll and b/Go/source/target/yitidgengo.dll differ diff --git a/Go/source/target/yitidgengo.h b/Go/source/target/yitidgengo.h index 647e9b9..950edd6 100644 --- a/Go/source/target/yitidgengo.h +++ b/Go/source/target/yitidgengo.h @@ -75,8 +75,8 @@ extern __declspec(dllexport) GoInt RegisterWorkerId(char* ip, GoInt port, char* // 注销WorkerId extern __declspec(dllexport) void UnRegisterWorkerId(); -// 检查本地WorkerId是否有效 -extern __declspec(dllexport) GoUint8 ValidateLocalWorkerId(GoInt workerId); +// 检查本地WorkerId是否有效(0-有效,其它-无效) +extern __declspec(dllexport) GoInt ValidateLocalWorkerId(GoInt workerId); #ifdef __cplusplus } diff --git a/README.md b/README.md index a31b30b..39e7616 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ ID示例(基于默认配置): #### 自动注册WorkerId -本算法提供一个开源的动态库(go实现),能在容器k8s环境下,通过 redis 自动注册 WorkerId。动态库提供的C接口方法有: +本算法提供一个开源的动态库(go语言实现),能在容器 k8s(或其它容器化集群) 环境下,通过 redis 自动注册 WorkerId。动态库提供的C接口方法有: ``` // 注册一个新的WorkerId