Skip to content

Commit c720f04

Browse files
authored
docs: change tags from key-value object to array of key-value pairs for improved consistency and flexibility
1 parent 57d3cbc commit c720f04

File tree

2 files changed

+72
-70
lines changed

2 files changed

+72
-70
lines changed

docs/en/api.md

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ API Key authentication is enabled by default, automatically generated and saved
6666
"status": "running|stopped|error",
6767
"url": "...",
6868
"restart": true,
69-
"tags": {
70-
"environment": "production",
71-
"region": "us-west-2",
72-
"project": "web-service"
73-
},
69+
"tags": [
70+
{"key": "environment", "value": "production"},
71+
{"key": "region", "value": "us-west-2"},
72+
{"key": "project", "value": "web-service"}
73+
],
7474
"mode": 0,
7575
"ping": 0,
7676
"pool": 0,
@@ -578,18 +578,18 @@ To properly manage lifecycles:
578578
return response.json();
579579
}
580580

581-
// Add or update tags - provide key-value pairs
582-
await updateInstanceTags('abc123', {
583-
environment: 'production',
584-
region: 'us-west-2',
585-
team: 'backend'
586-
});
581+
// Add or update tags - provide tag array
582+
await updateInstanceTags('abc123', [
583+
{"key": "environment", "value": "production"},
584+
{"key": "region", "value": "us-west-2"},
585+
{"key": "team", "value": "backend"}
586+
]);
587587

588-
// Delete tags - set values to empty string
589-
await updateInstanceTags('abc123', {
590-
'old-tag': '', // This tag will be removed
591-
'temp-tag': '' // This tag will be removed
592-
});
588+
// Replace all tags (remove existing, set new ones)
589+
await updateInstanceTags('abc123', [
590+
{"key": "environment", "value": "staging"},
591+
{"key": "version", "value": "2.0"}
592+
]);
593593
```
594594

595595
6. **Auto-restart Policy Management**: Configure automatic startup behavior
@@ -846,11 +846,12 @@ async function configureAutoStartPolicies(instances) {
846846
847847
### Tag Management Rules
848848
849-
1. **Adding Tags**: Provide new key-value pairs in the `tags` field to add them to the instance's tag collection
850-
2. **Updating Tags**: Provide new values for existing tag keys to overwrite the original values
851-
3. **Deleting Tags**: Set tag values to empty string (`""`) to remove them from the instance
852-
4. **Limits**: Maximum 50 tags, key names ≤100 characters, values ≤500 characters
853-
5. **Persistence**: All tag operations are automatically saved to disk and restored after restart
849+
1. **Replace Tags**: Provide tag array in the `tags` field to replace all instance tags
850+
2. **Array Format**: Tags now use array format `[{"key": "key1", "value": "value1"}]`
851+
3. **Uniqueness Check**: Duplicate keys are not allowed within the same instance
852+
4. **Clear Tags**: Provide empty array `[]` to remove all instance tags
853+
5. **Limits**: Maximum 50 tags, key names ≤100 characters, values ≤500 characters
854+
6. **Persistence**: All tag operations are automatically saved to disk and restored after restart
854855
855856
## Instance Data Structure
856857
@@ -864,11 +865,11 @@ The instance object in API responses contains the following fields:
864865
"status": "running", // Instance status: running, stopped, or error
865866
"url": "server://...", // Instance configuration URL
866867
"restart": true, // Auto-restart policy
867-
"tags": { // Tag key-value pairs
868-
"environment": "production",
869-
"project": "web-service",
870-
"region": "us-west-2"
871-
},
868+
"tags": [ // Tag array
869+
{"key": "environment", "value": "production"},
870+
{"key": "project", "value": "web-service"},
871+
{"key": "region", "value": "us-west-2"}
872+
],
872873
"mode": 0, // Instance mode
873874
"tcprx": 1024, // TCP received bytes
874875
"tcptx": 2048, // TCP transmitted bytes
@@ -1066,7 +1067,7 @@ const instance = await fetch(`${API_URL}/instances/abc123`, {
10661067
#### PATCH /instances/{id}
10671068
- **Description**: Update instance state, alias, tags, or perform control operations
10681069
- **Authentication**: Requires API Key
1069-
- **Request body**: `{ "alias": "new alias", "action": "start|stop|restart|reset", "restart": true|false, "tags": {"key": "value"} }`
1070+
- **Request body**: `{ "alias": "new alias", "action": "start|stop|restart|reset", "restart": true|false, "tags": [{"key": "key1", "value": "value1"}] }`
10701071
- **Example**:
10711072
```javascript
10721073
// Update tags
@@ -1077,25 +1078,25 @@ await fetch(`${API_URL}/instances/abc123`, {
10771078
'X-API-Key': apiKey
10781079
},
10791080
body: JSON.stringify({
1080-
tags: {
1081-
environment: 'production',
1082-
region: 'us-west-2'
1083-
}
1081+
tags: [
1082+
{"key": "environment", "value": "production"},
1083+
{"key": "region", "value": "us-west-2"}
1084+
]
10841085
})
10851086
});
10861087

1087-
// Delete tags (set to empty string)
1088+
// Replace all tags with new ones
10881089
await fetch(`${API_URL}/instances/abc123`, {
10891090
method: 'PATCH',
10901091
headers: {
10911092
'Content-Type': 'application/json',
10921093
'X-API-Key': apiKey
10931094
},
10941095
body: JSON.stringify({
1095-
tags: {
1096-
'old-tag': '', // Will be deleted
1097-
'temp-tag': '' // Will be deleted
1098-
}
1096+
tags: [
1097+
{"key": "environment", "value": "staging"},
1098+
{"key": "version", "value": "2.0"}
1099+
]
10991100
})
11001101
});
11011102
```

docs/zh/api.md

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ API Key 认证默认启用,首次启动自动生成并保存在 `nodepass.gob`
6666
"status": "running|stopped|error",
6767
"url": "...",
6868
"restart": true,
69-
"tags": {
70-
"environment": "production",
71-
"region": "us-west-2",
72-
"project": "web-service"
73-
},
69+
"tags": [
70+
{"key": "environment", "value": "production"},
71+
{"key": "region", "value": "us-west-2"},
72+
{"key": "project", "value": "web-service"}
73+
],
7474
"mode": 0,
7575
"ping": 0,
7676
"pool": 0,
@@ -577,18 +577,18 @@ NodePass主控模式提供自动备份功能,定期备份状态文件以防止
577577
return response.json();
578578
}
579579

580-
// 添加或更新标签 - 提供键值对
581-
await updateInstanceTags('abc123', {
582-
environment: 'production',
583-
region: 'us-west-2',
584-
team: 'backend'
585-
});
580+
// 添加或更新标签 - 提供标签数组
581+
await updateInstanceTags('abc123', [
582+
{"key": "environment", "value": "production"},
583+
{"key": "region", "value": "us-west-2"},
584+
{"key": "team", "value": "backend"}
585+
]);
586586

587-
// 删除标签 - 设置值为空字符串
588-
await updateInstanceTags('abc123', {
589-
'old-tag': '', // 此标签将被删除
590-
'temp-tag': '' // 此标签将被删除
591-
});
587+
// 替换所有标签(删除现有,设置新的)
588+
await updateInstanceTags('abc123', [
589+
{"key": "environment", "value": "staging"},
590+
{"key": "version", "value": "2.0"}
591+
]);
592592
```
593593

594594
6. **自启动策略管理**:配置自动启动行为
@@ -845,9 +845,10 @@ async function configureAutoStartPolicies(instances) {
845845
846846
### 标签管理规则
847847
848-
1. **添加标签**:在`tags`字段中提供新的键值对,将自动添加到实例的标签集合中
849-
2. **更新标签**:提供已存在标签键的新值,将覆盖原有值
850-
3. **删除标签**:设置标签值为空字符串(`""`),该标签将从实例中移除
848+
1. **替换标签**:在`tags`字段中提供标签数组,将替换实例的所有标签
849+
2. **数组格式**:标签现在使用数组格式 `[{"key": "key1", "value": "value1"}]`
850+
3. **唯一性检查**:同一个实例中不允许重复的键名
851+
4. **清空标签**:提供空数组`[]`将删除实例的所有标签
851852
4. **限制**:最多50个标签,键名长度≤100字符,值长度≤500字符
852853
5. **持久化**:所有标签操作自动保存到磁盘,重启后恢复
853854
@@ -863,11 +864,11 @@ API响应中的实例对象包含以下字段:
863864
"status": "running", // 实例状态:running、stopped 或 error
864865
"url": "server://...", // 实例配置URL
865866
"restart": true, // 自启动策略
866-
"tags": { // 标签键值对
867-
"environment": "production",
868-
"project": "web-service",
869-
"region": "us-west-2"
870-
},
867+
"tags": [ // 标签数组
868+
{"key": "environment", "value": "production"},
869+
{"key": "project", "value": "web-service"},
870+
{"key": "region", "value": "us-west-2"}
871+
],
871872
"mode": 0, // 运行模式
872873
"tcprx": 1024, // TCP接收字节数
873874
"tcptx": 2048, // TCP发送字节数
@@ -1065,7 +1066,7 @@ const instance = await fetch(`${API_URL}/instances/abc123`, {
10651066
#### PATCH /instances/{id}
10661067
- **描述**:更新实例状态、别名、标签或执行控制操作
10671068
- **认证**:需要API Key
1068-
- **请求体**:`{ "alias": "新别名", "action": "start|stop|restart|reset", "restart": true|false, "tags": {"": ""} }`
1069+
- **请求体**:`{ "alias": "新别名", "action": "start|stop|restart|reset", "restart": true|false, "tags": [{"key": "", "value": ""}] }`
10691070
- **示例**:
10701071
```javascript
10711072
// 更新标签
@@ -1076,25 +1077,25 @@ await fetch(`${API_URL}/instances/abc123`, {
10761077
'X-API-Key': apiKey
10771078
},
10781079
body: JSON.stringify({
1079-
tags: {
1080-
environment: 'production',
1081-
region: 'us-west-2'
1082-
}
1080+
tags: [
1081+
{"key": "environment", "value": "production"},
1082+
{"key": "region", "value": "us-west-2"}
1083+
]
10831084
})
10841085
});
10851086

1086-
// 删除标签(设置为空字符串)
1087+
// 替换所有标签为新标签
10871088
await fetch(`${API_URL}/instances/abc123`, {
10881089
method: 'PATCH',
10891090
headers: {
10901091
'Content-Type': 'application/json',
10911092
'X-API-Key': apiKey
10921093
},
10931094
body: JSON.stringify({
1094-
tags: {
1095-
'old-tag': '', // 将被删除
1096-
'temp-tag': '' // 将被删除
1097-
}
1095+
tags: [
1096+
{"key": "environment", "value": "staging"},
1097+
{"key": "version", "value": "2.0"}
1098+
]
10981099
})
10991100
});
11001101
```

0 commit comments

Comments
 (0)