This page documents the ~170 auto-generated API methods in the go-dota2 client that provide typed, convenient access to the Dota 2 Game Coordinator protocol. These methods are automatically generated from Protocol Buffer message definitions and provide two interaction patterns: fire-and-forget actions and request-response queries.
For information about the core client methods (New, GetCache, Close, etc.), see 3.1 Core Client Methods For information about the code generation infrastructure that produces these methods, see 5.1 API Generator (apigen)
The generated API methods in client_generated.go1-319367 provide a complete, type-safe interface to the Dota 2 Game Coordinator. Each method corresponds to a specific GC message type defined in the protocol buffers. The API generator automatically produces these methods by analyzing the protocol definitions and applying heuristics and manual overrides to determine the correct method signature and behavior.
Sources: client_generated.go1-100 apigen/msg_overrides.go1-243
The generated API is divided into two distinct patterns based on the underlying message semantics:
Fire-and-forget methods send a message to the Game Coordinator without expecting a response. These methods:
d.write() directly client_generated.go16Example - Lobby Abandonment:
Example - Party Invite Cancellation:
Sources: client_generated.go11-17 client_generated.go146-158 client_generated.go28
Request-response methods send a message and wait for a corresponding response from the Game Coordinator. These methods:
context.Context as the first parameter for cancellation and timeout control client_generated.go51error client_generated.go56MakeRequest pattern to handle request/response correlation client_request.go17-90Example - Autograph Reward Query:
Sources: client_generated.go91-107 client_request.go17-90
The following diagram illustrates how protocol definitions and manual overrides are transformed into the final Go API.
Code Entity Mapping Diagram
Sources: apigen/msg_overrides.go10-123 apigen/msg_overrides.go126-144 apigen/msg_overrides.go148-159 client_generated.go1-100
All request-response methods accept a context.Context as their first parameter. This enables:
| Context Feature | Use Case | Implementation Detail |
|---|---|---|
| Timeout | Prevent indefinite blocking | Handled in select block client_request.go82-89 |
| Cancellation | Abort in-flight requests | Checked via ctx.Done() client_request.go83-85 |
| Session Sync | Ensure client is connected | Checked via cctx (connection context) client_request.go26-29 |
Example Usage:
Sources: client_request.go17-90 client_generated.go91-107
The generated methods can be categorized by functional domain based on the EDOTAGCMsg they implement.
Natural Language to Code Entity Space
Sources: client_generated.go11-215 apigen/msg_overrides.go126-144
The API generator uses several override maps in apigen/msg_overrides.go to handle special cases and correct automatic heuristics:
The msgSenderOverrides map specifies which party sends each message. Messages marked as MsgSenderNone are excluded from the Dota2 client generation as they are typically server-to-GC or inter-GC messages apigen/msg_overrides.go10-123
| Sender Type | Meaning | Example |
|---|---|---|
MsgSenderClient | Client sends to GC | k_EMsgGCAbandonCurrentGame apigen/msg_overrides.go35 |
MsgSenderGC | GC sends to client | k_EMsgGCOtherJoinedChannel apigen/msg_overrides.go21 |
MsgSenderNone | Internal/Server only | k_EMsgGCLiveScoreboardUpdate apigen/msg_overrides.go11 |
The msgMethodNameOverrides map provides custom method names for better readability or to match established Dota 2 terminology apigen/msg_overrides.go126-144
| Message ID | Generated Name | Override Name |
|---|---|---|
k_EMsgGCAbandonCurrentGame | AbandonCurrentGame | AbandonLobby apigen/msg_overrides.go130 |
k_EMsgGCReadyUp | ReadyUp | SendReadyUp apigen/msg_overrides.go129 |
k_EMsgDestroyLobbyRequest | DestroyLobbyRequest | DestroyLobby apigen/msg_overrides.go128 |
Sources: apigen/msg_overrides.go126-144
The msgResponseOverrides map explicitly pairs request messages with their response messages, enabling the MakeRequest pattern apigen/msg_overrides.go148-159
Sources: apigen/msg_overrides.go148-159
When a protobuf message has simple scalar fields, they are extracted as individual parameters in the Go function signature client_generated.go34-43
When a protobuf message is complex or marked in msgArgAsParameterOverrides, the entire request message is passed as a pointer apigen/msg_overrides.go232-235
Sources: client_generated.go34-43 apigen/msg_overrides.go232-235
Request-response methods return errors in several scenarios:
| Error | Meaning |
|---|---|
ErrNotReady | The client is not currently connected to the GC client_request.go86-87 |
context.DeadlineExceeded | The GC did not respond within the provided context timeout client_request.go83-84 |
unmarshal error | The response body could not be parsed into the expected proto message client_request.go64-67 |
Sources: client_request.go26-29 client_request.go64-67 client_request.go82-89
Refresh this wiki