add go examples

This commit is contained in:
zekro committed 2026-07-16 10:59:34 +02:00
1 parent 6eef7e38a7
commit 3d8aa85358
6 files changed
+111

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
enum OpCode {
PING,
HELLO,
MOVE,
}
type HelloEvent = {
name: string;
};
type MoveEvent = {
x: number;
y: number;
};
type OpArgsMapping = {
[OpCode.PING]: null;
[OpCode.HELLO]: HelloEvent;
[OpCode.MOVE]: MoveEvent;
};
class WebSocketClient {
public op<TOp extends OpCode, TArgs extends OpArgsMapping[TOp]>(
op: TOp,
args: TArgs,
) {
// ...
}
}
function main() {
const client = new WebSocketClient();
client.op(OpCode.HELLO, { name: "foo" });
}