Skip to content

Instantly share code, notes, and snippets.

@Jimeux
Last active December 22, 2021 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jimeux/86b8b82deea446448faad46126db790e to your computer and use it in GitHub Desktop.
Save Jimeux/86b8b82deea446448faad46126db790e to your computer and use it in GitHub Desktop.
// WebSocketService implements the core logic of svc-ws.
type WebSocketService struct {
client *Client
repository *Repository
}
func NewWebSocketService(client *Client, repository *Repository) *WebSocketService {
return &WebSocketService{
client: client,
repository: repository,
}
}
// Connect saves a reference to connID in the datastore.
func (s *WebSocketService) Connect(ctx context.Context, connID string) (Response, error) {
// save connection initially without username
if err := s.repository.SaveConnection(ctx, connID, ""); err != nil {
return ResponseInternalServerError(), fmt.Errorf("failed to connect connectionID %s: %w", connID, err)
}
return ResponseOK(), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment