add go examples
This commit is contained in:
1 parent
6eef7e38a7
commit
3d8aa85358
6 files changed
+111
No files matched your search
@@ -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" });
|
||||
}
|
||||
Reference in new issue
Block a user