# Device SDK for Go

## 安装 
`go import "license-server/sdk/go/devicesdk"`

## 基本用法

### 初始化客户端
```go
client := devicesdk.NewDeviceClient(
"http://localhost:8080",
"your-32-byte-encrypt-key-here123456",
)
```
### 设备注册
```go
// 不带授权码注册
err := client.RegisterDevice(&devicesdk.DeviceInfo{
UID: "device-001",
DeviceModel: "test-model",
})
if err != nil {
log.Fatalf("设备注册失败: %v", err)
}
// 带授权码注册
err = client.RegisterDevice(&devicesdk.DeviceInfo{
UID: "device-002",
DeviceModel: "test-model",
LicenseCode: "your-license-code", // 可选
})
if err != nil {
log.Fatalf("设备注册失败: %v", err)
}
```
### 设备验证
```go
validateResp, err := client.ValidateDevice("device-001")
if err != nil {
log.Fatalf("设备验证失败: %v", err)
}
fmt.Printf("设备状态: %s\n", validateResp.Status)
fmt.Printf("授权类型: %s\n", validateResp.LicenseType)
fmt.Printf("过期时间: %s\n", validateResp.ExpireTime)
```
### 更新启动次数
```go
count, err := client.UpdateStartCount("device-001")
if err != nil {
log.Fatalf("更新启动次数失败: %v", err)
}
fmt.Printf("当前启动次数: %d\n", count)
```

### 绑定授权码
```go
err := client.BindLicense("device-001", "your-license-code")
if err != nil {
log.Fatalf("绑定授权码失败: %v", err)
}
```
## 完整示例
```go
package main
import (
"fmt"
"log"
"license-server/sdk/go/devicesdk"
)
func main() {
client := devicesdk.NewDeviceClient(
"http://localhost:8080",
"your-32-byte-encrypt-key-here123456",
)
// 注册设备
err := client.RegisterDevice(&devicesdk.DeviceInfo{
UID: "device-001",
DeviceModel: "test-model",
})
if err != nil {
log.Fatalf("设备注册失败: %v", err)
}
fmt.Println("设备注册成功")
// 绑定授权码
err = client.BindLicense("device-001", "license-code-123")
if err != nil {
log.Fatalf("绑定授权码失败: %v", err)
}
fmt.Println("授权码绑定成功")
// 验证设备
validateResp, err := client.ValidateDevice("device-001")
if err != nil {
log.Fatalf("设备验证失败: %v", err)
}
fmt.Printf("设备状态: %s\n", validateResp.Status)
fmt.Printf("授权类型: %s\n", validateResp.LicenseType)
fmt.Printf("过期时间: %s\n", validateResp.ExpireTime)
// 更新启动次数
count, err := client.UpdateStartCount("device-001")
if err != nil {
log.Fatalf("更新启动次数失败: %v", err)
}
fmt.Printf("当前启动次数: %d\n", count)
}
```