@@ -34,12 +34,14 @@ type Message struct {
3434 Timestamp time.Time `json:"timestamp"`
3535}
3636
37- // Config holds subscription manager configuration
38- type Config struct {
37+ // ManagerConfig holds subscription manager configuration
38+ type ManagerConfig struct {
3939 ServerURL string
4040 ReplicaPath string
4141 AuthToken string
4242 ReplicaID string
43+ WsID string // websocket ID for client identification
44+ ClientVersion string // version of the client software
4345 Logger * zap.Logger
4446 MaxReconnectAttempts int // Maximum number of reconnect attempts (0 = infinite)
4547 InitialReconnectDelay time.Duration // Initial delay before first reconnect
@@ -54,7 +56,7 @@ type Config struct {
5456// MaxReconnectDelay is reached. Reconnection attempts continue indefinitely unless
5557// MaxReconnectAttempts is set to a positive value.
5658type Manager struct {
57- config * Config
59+ config * ManagerConfig
5860 logger * zap.Logger
5961 conn * websocket.Conn
6062 ctx context.Context
@@ -73,7 +75,7 @@ type Manager struct {
7375}
7476
7577// NewManager creates a new subscription manager
76- func NewManager (config * Config ) * Manager {
78+ func NewManager (config * ManagerConfig ) * Manager {
7779 ctx , cancel := context .WithCancel (context .Background ())
7880
7981 // Set default reconnection parameters if not provided
@@ -202,6 +204,9 @@ func (m *Manager) doConnect() error {
202204 headers .Set ("X-ReplicaID" , m .config .ReplicaID )
203205 }
204206
207+ headers .Set ("X-ClientVersion" , m .config .ClientVersion )
208+ headers .Set ("X-ClientID" , m .config .WsID )
209+
205210 dialer := websocket.Dialer {
206211 HandshakeTimeout : 10 * time .Second ,
207212 }
@@ -214,7 +219,7 @@ func (m *Manager) doConnect() error {
214219 // Extract detailed error information from the response
215220 statusCode := response .StatusCode
216221 statusText := response .Status
217-
222+
218223 var respBodyStr string
219224 if response .Body != nil {
220225 respBytes , readErr := io .ReadAll (response .Body )
@@ -223,22 +228,22 @@ func (m *Manager) doConnect() error {
223228 respBodyStr = strings .TrimSpace (string (respBytes ))
224229 }
225230 }
226-
231+
227232 // Create a clean error message
228233 var errorMsg strings.Builder
229234 errorMsg .WriteString (fmt .Sprintf ("HTTP %d (%s)" , statusCode , statusText ))
230-
235+
231236 if respBodyStr != "" {
232237 errorMsg .WriteString (fmt .Sprintf (": %s" , respBodyStr ))
233238 }
234-
239+
235240 return fmt .Errorf ("%s" , errorMsg .String ())
236241 }
237-
242+
238243 // Handle cases where response is nil (e.g., network errors, bad handshake)
239244 var errorMsg strings.Builder
240245 errorMsg .WriteString ("Failed to connect to subscription service" )
241-
246+
242247 // Analyze the error type and provide helpful context
243248 errorStr := err .Error ()
244249 if strings .Contains (errorStr , "bad handshake" ) {
@@ -258,9 +263,9 @@ func (m *Manager) doConnect() error {
258263 errorMsg .WriteString (" - DNS resolution failed" )
259264 errorMsg .WriteString ("\n Check the server hostname in your configuration" )
260265 }
261-
266+
262267 errorMsg .WriteString (fmt .Sprintf ("\n Original error: %v" , err ))
263-
268+
264269 return fmt .Errorf ("%s" , errorMsg .String ())
265270 }
266271
0 commit comments