Skip to content

Commit 6d87939

Browse files
committed
style(sdks): use camelCase payload keys across demo examples
Game payload keys are outside the platform naming contract, but the bundled demos set the example integrators copy. Normalize every demo (go/js/python/java/cpp/csharp), invoker example and test fixture from snake_case (player_id, page_size, template_id, ...) to camelCase so generated forms and docs stay consistent. Item template id strings (gold_coin, hero_ticket) are business identifiers and stay unchanged.
1 parent cf005f5 commit 6d87939

17 files changed

Lines changed: 418 additions & 417 deletions

File tree

sdks/cpp/examples/game_demo.cpp

Lines changed: 50 additions & 50 deletions
Large diffs are not rendered by default.

sdks/csharp/examples/GameDemo/Program.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static async Task<int> Main(string[] args)
172172
{
173173
("player.create", "warning", "player", "create", async (ctx, payload) => {
174174
var body = H.Parse(payload);
175-
var id = H.Str(body, "id", "player_id");
175+
var id = H.Str(body, "id", "playerId");
176176
if (id == "") id = store.NextPlayerId();
177177
var now = H.Now();
178178
var r = new PlayerRecord(id, H.NonEmpty(H.Str(body, "name"), $"Player-{id}"),
@@ -184,14 +184,14 @@ static async Task<int> Main(string[] args)
184184
}),
185185
("player.get", "safe", "player", "get", async (ctx, payload) => {
186186
var body = H.Parse(payload);
187-
var id = H.Str(body, "player_id", "id");
187+
var id = H.Str(body, "playerId", "id");
188188
if (!store.Players.TryGetValue(id, out var r))
189189
return H.Resp(new() { ["status"] = "not_found", ["message"] = "player not found" });
190190
return H.Resp(new() { ["status"] = "success", ["action"] = "player.get", ["player"] = r });
191191
}),
192192
("player.update", "warning", "player", "update", async (ctx, payload) => {
193193
var body = H.Parse(payload);
194-
var id = H.Str(body, "player_id", "id");
194+
var id = H.Str(body, "playerId", "id");
195195
if (!store.Players.TryGetValue(id, out var r))
196196
return H.Resp(new() { ["status"] = "not_found", ["message"] = "player not found" });
197197
var name = H.Str(body, "name"); if (name != "") r = r with { Name = name };
@@ -207,10 +207,10 @@ static async Task<int> Main(string[] args)
207207
}),
208208
("player.delete", "danger", "player", "delete", async (ctx, payload) => {
209209
var body = H.Parse(payload);
210-
var id = H.Str(body, "player_id", "id");
210+
var id = H.Str(body, "playerId", "id");
211211
store.Players.TryRemove(id, out _); store.Inventories.TryRemove(id, out _);
212212
store.Mails.TryRemove(id, out _); store.Leaderboard.TryRemove(id, out _);
213-
return H.Resp(new() { ["status"] = "success", ["action"] = "player.delete", ["player_id"] = id });
213+
return H.Resp(new() { ["status"] = "success", ["action"] = "player.delete", ["playerId"] = id });
214214
}),
215215
("player.list", "safe", "player", "list", async (ctx, payload) => {
216216
var items = store.Players.Values.OrderBy(p => p.Id).ToList();
@@ -222,8 +222,8 @@ static async Task<int> Main(string[] args)
222222
var id = H.Str(body, "order_id", "id");
223223
if (id == "") id = store.NextOrderId();
224224
var now = H.Now();
225-
var r = new OrderRecord(id, H.Str(body, "player_id"),
226-
H.NonEmpty(H.Str(body, "product_id"), "product.demo"),
225+
var r = new OrderRecord(id, H.Str(body, "playerId"),
226+
H.NonEmpty(H.Str(body, "productId"), "product.demo"),
227227
H.Long(body, 0, "amount"), H.NonEmpty(H.Str(body, "currency"), "CNY"),
228228
H.NonEmpty(H.Str(body, "status"), "created"), H.NonEmpty(H.Str(body, "channel"), "gm"),
229229
now, now, H.Map(body, "attributes"));
@@ -258,7 +258,7 @@ static async Task<int> Main(string[] args)
258258
}),
259259
("order.list", "safe", "order", "list", async (ctx, payload) => {
260260
var body = H.Parse(payload);
261-
var pid = H.Str(body, "player_id");
261+
var pid = H.Str(body, "playerId");
262262
var items = store.Orders.Values.Where(o => pid == "" || o.PlayerId == pid).OrderBy(o => o.Id).ToList();
263263
return H.Resp(new() { ["status"] = "success", ["action"] = "order.list", ["items"] = items, ["total"] = items.Count });
264264
}),
@@ -270,7 +270,7 @@ static async Task<int> Main(string[] args)
270270
}),
271271
("leaderboard.upsert", "warning", "leaderboard", "upsert", async (ctx, payload) => {
272272
var body = H.Parse(payload);
273-
var pid = H.Str(body, "player_id");
273+
var pid = H.Str(body, "playerId");
274274
if (pid == "") throw new ArgumentException("player_id is required");
275275
var pname = pid;
276276
if (store.Players.TryGetValue(pid, out var p) && p.Name != "") pname = p.Name;
@@ -285,62 +285,62 @@ static async Task<int> Main(string[] args)
285285

286286
("inventory.list", "safe", "inventory", "list", async (ctx, payload) => {
287287
var body = H.Parse(payload);
288-
var pid = H.Str(body, "player_id");
288+
var pid = H.Str(body, "playerId");
289289
if (pid == "") throw new ArgumentException("player_id is required");
290290
var items = store.Inventories.TryGetValue(pid, out var inv)
291291
? inv.Values.OrderBy(i => i.TemplateId).ToList() : new List<ItemRecord>();
292-
return H.Resp(new() { ["status"] = "success", ["action"] = "inventory.list", ["player_id"] = pid, ["items"] = items });
292+
return H.Resp(new() { ["status"] = "success", ["action"] = "inventory.list", ["playerId"] = pid, ["items"] = items });
293293
}),
294294
("inventory.grant", "warning", "inventory", "grant", async (ctx, payload) => {
295295
var body = H.Parse(payload);
296-
var pid = H.Str(body, "player_id");
297-
var tid = H.Str(body, "template_id", "item_id");
296+
var pid = H.Str(body, "playerId");
297+
var tid = H.Str(body, "templateId", "item_id");
298298
if (pid == "" || tid == "") throw new ArgumentException("player_id and template_id are required");
299299
var inv = store.Inventories.GetOrAdd(pid, _ => new());
300300
var qty = H.Long(body, 1, "quantity");
301301
inv.AddOrUpdate(tid,
302302
_ => new ItemRecord($"item_{tid}", tid, H.NonEmpty(H.Str(body, "name"), tid), qty,
303303
H.NonEmpty(H.Str(body, "rarity"), "common"), H.Now()),
304304
(_, existing) => existing with { Quantity = existing.Quantity + qty, UpdatedAt = H.Now() });
305-
return H.Resp(new() { ["status"] = "success", ["action"] = "inventory.grant", ["player_id"] = pid, ["item"] = inv[tid] });
305+
return H.Resp(new() { ["status"] = "success", ["action"] = "inventory.grant", ["playerId"] = pid, ["item"] = inv[tid] });
306306
}),
307307
("inventory.consume", "warning", "inventory", "consume", async (ctx, payload) => {
308308
var body = H.Parse(payload);
309-
var pid = H.Str(body, "player_id");
310-
var tid = H.Str(body, "template_id", "item_id");
309+
var pid = H.Str(body, "playerId");
310+
var tid = H.Str(body, "templateId", "item_id");
311311
var qty = H.Long(body, 1, "quantity");
312312
if (pid == "" || tid == "") throw new ArgumentException("player_id and template_id are required");
313313
if (!store.Inventories.TryGetValue(pid, out var inv) || !inv.TryGetValue(tid, out var r))
314314
return H.Resp(new() { ["status"] = "not_found", ["message"] = "item not found" });
315315
if (r.Quantity < qty)
316316
return H.Resp(new() { ["status"] = "failed", ["message"] = "insufficient quantity" });
317317
inv[tid] = r with { Quantity = r.Quantity - qty, UpdatedAt = H.Now() };
318-
return H.Resp(new() { ["status"] = "success", ["action"] = "inventory.consume", ["player_id"] = pid, ["item"] = inv[tid] });
318+
return H.Resp(new() { ["status"] = "success", ["action"] = "inventory.consume", ["playerId"] = pid, ["item"] = inv[tid] });
319319
}),
320320

321321
("mail.send", "warning", "mail", "send", async (ctx, payload) => {
322322
var body = H.Parse(payload);
323-
var pid = H.Str(body, "player_id");
323+
var pid = H.Str(body, "playerId");
324324
if (pid == "") throw new ArgumentException("player_id is required");
325325
var now = H.Now();
326326
var r = new MailRecord(store.NextMailId(), pid,
327327
H.NonEmpty(H.Str(body, "title"), "系统邮件"),
328328
H.NonEmpty(H.Str(body, "content"), "请查收奖励"),
329-
"unread", H.Map(body, "reward"), now, now, H.Str(body, "expire_at"));
329+
"unread", H.Map(body, "reward"), now, now, H.Str(body, "expireAt"));
330330
store.Mails.AddOrUpdate(pid, _ => new List<MailRecord> { r }, (_, list) => { lock (list) { list.Add(r); } return list; });
331331
return H.Resp(new() { ["status"] = "success", ["action"] = "mail.send", ["mail"] = r });
332332
}),
333333
("mail.list", "safe", "mail", "list", async (ctx, payload) => {
334334
var body = H.Parse(payload);
335-
var pid = H.Str(body, "player_id");
335+
var pid = H.Str(body, "playerId");
336336
if (pid == "") throw new ArgumentException("player_id is required");
337337
List<MailRecord> items = new();
338338
if (store.Mails.TryGetValue(pid, out var list)) lock (list) { items = list.ToList(); }
339-
return H.Resp(new() { ["status"] = "success", ["action"] = "mail.list", ["player_id"] = pid, ["items"] = items, ["total"] = items.Count });
339+
return H.Resp(new() { ["status"] = "success", ["action"] = "mail.list", ["playerId"] = pid, ["items"] = items, ["total"] = items.Count });
340340
}),
341341
("mail.claim", "warning", "mail", "claim", async (ctx, payload) => {
342342
var body = H.Parse(payload);
343-
var pid = H.Str(body, "player_id");
343+
var pid = H.Str(body, "playerId");
344344
var mid = H.Str(body, "mail_id", "id");
345345
if (pid == "" || mid == "") throw new ArgumentException("player_id and mail_id are required");
346346
if (store.Mails.TryGetValue(pid, out var list))
@@ -418,7 +418,7 @@ static void EnrichDescriptor(FunctionDescriptor desc)
418418

419419
static string InputSchemaFor(string resource, string operation)
420420
{
421-
var idKey = resource == "inventory" ? "player_id" : $"{resource}_id";
421+
var idKey = resource == "inventory" ? "playerId" : $"{resource}_id";
422422
return operation switch
423423
{
424424
"create" => $"{{\"type\":\"object\",\"properties\":{{\"{idKey}\":{{\"type\":\"string\"}},\"data\":{{\"type\":\"object\"}}}}}}",

sdks/csharp/examples/SimpleService/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
Console.WriteLine($"[player.get] Call: {context.CallId}, Payload: {payload}");
5555

5656
// 解析请求(简化版,实际应使用 JSON 库)
57-
// payload: {"player_id": "12345"}
57+
// payload: {"playerId": "12345"}
5858

5959
// 模拟处理
6060
await Task.Delay(10);

sdks/go/examples/basic/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func registerFunctions(client croupier.Client) error {
113113
result := fmt.Sprintf(`{
114114
"status": "success",
115115
"action": "create",
116-
"item_id": "item_%d",
116+
"itemId": "item_%d",
117117
"timestamp": "%s"
118118
}`, time.Now().Unix(), time.Now().Format(time.RFC3339))
119119

sdks/go/examples/comprehensive/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func playerBanHandler(ctx context.Context, payload []byte) ([]byte, error) {
3333
result := map[string]interface{}{
3434
"status": "success",
3535
"action": "ban",
36-
"player_id": "player_123",
36+
"playerId": "player_123",
3737
"reason": "违规行为",
3838
"timestamp": time.Now().Format(time.RFC3339),
3939
}
@@ -48,7 +48,7 @@ func itemCreateHandler(ctx context.Context, payload []byte) ([]byte, error) {
4848
result := map[string]interface{}{
4949
"status": "success",
5050
"action": "create",
51-
"item_id": fmt.Sprintf("item_%d", time.Now().Unix()),
51+
"itemId": fmt.Sprintf("item_%d", time.Now().Unix()),
5252
"type": "weapon",
5353
"timestamp": time.Now().Format(time.RFC3339),
5454
}
@@ -62,7 +62,7 @@ func playerDataHandler(ctx context.Context, payload []byte) ([]byte, error) {
6262

6363
result := map[string]interface{}{
6464
"status": "success",
65-
"player_id": "player_123",
65+
"playerId": "player_123",
6666
"level": 50,
6767
"exp": 125000,
6868
"timestamp": time.Now().Format(time.RFC3339),
@@ -250,10 +250,10 @@ func demonstrateInvokerInterface(ctx context.Context) error {
250250
banSchema := map[string]interface{}{
251251
"type": "object",
252252
"properties": map[string]interface{}{
253-
"player_id": map[string]interface{}{"type": "string"},
254-
"reason": map[string]interface{}{"type": "string"},
253+
"playerId": map[string]interface{}{"type": "string"},
254+
"reason": map[string]interface{}{"type": "string"},
255255
},
256-
"required": []string{"player_id", "reason"},
256+
"required": []string{"playerId", "reason"},
257257
}
258258

259259
if err := invoker.SetSchema("player.ban", banSchema); err != nil {
@@ -273,8 +273,8 @@ func demonstrateInvokerInterface(ctx context.Context) error {
273273
}
274274

275275
payload := map[string]interface{}{
276-
"player_id": "player_123",
277-
"reason": "违规聊天",
276+
"playerId": "player_123",
277+
"reason": "违规聊天",
278278
}
279279
payloadJSON, _ := json.Marshal(payload)
280280

0 commit comments

Comments
 (0)