Browse Source

auto commit

tags/v1.0.0
yitter 3 years ago
parent
commit
29ec38cd07
5 changed files with 12 additions and 8 deletions
  1. +3
    -3
      Go/source/main.go
  2. +6
    -2
      Go/source/regworkerid/reghelper.go
  3. BIN
      Go/source/target/yitidgengo.dll
  4. +2
    -2
      Go/source/target/yitidgengo.h
  5. +1
    -1
      README.md

+ 3
- 3
Go/source/main.go View File

@@ -23,7 +23,7 @@ func NextId() uint64 {
// 注册一个新的WorkerId // 注册一个新的WorkerId
//export RegisterWorkerId //export RegisterWorkerId
func RegisterWorkerId(ip *C.char, port int, password *C.char, maxWorkerId int) int { 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 // 注销WorkerId
@@ -32,9 +32,9 @@ func UnRegisterWorkerId() {
regworkerid.UnRegisterWorkerId() regworkerid.UnRegisterWorkerId()
} }


// 检查本地WorkerId是否有效
// 检查本地WorkerId是否有效(0-有效,其它-无效)
//export ValidateLocalWorkerId //export ValidateLocalWorkerId
func ValidateLocalWorkerId(workerId int) bool {
func ValidateLocalWorkerId(workerId int) int {
return regworkerid.ValidateLocalWorkerId(workerId) return regworkerid.ValidateLocalWorkerId(workerId)
} }




+ 6
- 2
Go/source/regworkerid/reghelper.go View File

@@ -26,8 +26,12 @@ const _WorkerIdValueKeyPrefix string = "IdGen:WorkerId:Value:" // redis 中的ke
const _WorkerIdFlag = "Y" // IdGen:WorkerId:Value:xx 的值(将来可用 _token 替代) const _WorkerIdFlag = "Y" // IdGen:WorkerId:Value:xx 的值(将来可用 _token 替代)
const _Log = false // 是否输出日志 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() { func UnRegisterWorkerId() {


BIN
Go/source/target/yitidgengo.dll View File


+ 2
- 2
Go/source/target/yitidgengo.h View File

@@ -75,8 +75,8 @@ extern __declspec(dllexport) GoInt RegisterWorkerId(char* ip, GoInt port, char*
// 注销WorkerId // 注销WorkerId
extern __declspec(dllexport) void UnRegisterWorkerId(); extern __declspec(dllexport) void UnRegisterWorkerId();


// 检查本地WorkerId是否有效
extern __declspec(dllexport) GoUint8 ValidateLocalWorkerId(GoInt workerId);
// 检查本地WorkerId是否有效(0-有效,其它-无效)
extern __declspec(dllexport) GoInt ValidateLocalWorkerId(GoInt workerId);


#ifdef __cplusplus #ifdef __cplusplus
} }


+ 1
- 1
README.md View File

@@ -168,7 +168,7 @@ ID示例(基于默认配置):


#### 自动注册WorkerId #### 自动注册WorkerId


本算法提供一个开源的动态库(go实现),能在容器k8s环境下,通过 redis 自动注册 WorkerId。动态库提供的C接口方法有:
本算法提供一个开源的动态库(go语言实现),能在容器 k8s(或其它容器化集群) 环境下,通过 redis 自动注册 WorkerId。动态库提供的C接口方法有:
``` ```


// 注册一个新的WorkerId // 注册一个新的WorkerId


Loading…
Cancel
Save