(ctx context.Context, conn *websocket.Conn)
| 52 | type HandleWebsocketMessage func([]byte) error |
| 53 | |
| 54 | func NewClient(ctx context.Context, conn *websocket.Conn) (*Client, error) { |
| 55 | clientID := uuid.New() |
| 56 | consumerID := fmt.Sprintf("ws-client-watcher-%s", clientID.String()) |
| 57 | |
| 58 | user := auth.UserID(ctx) |
| 59 | if user == "" { |
| 60 | return nil, fmt.Errorf("user not found in context") |
| 61 | } |
| 62 | generation := auth.PasswordGeneration(ctx) |
| 63 | |
| 64 | consumer, err := watcher.RegisterConsumer( |
| 65 | ctx, consumerID, |
| 66 | watcher.WithUserIDFilter(user), |
| 67 | ) |
| 68 | if err != nil { |
| 69 | return nil, fmt.Errorf("error registering consumer: %w", err) |
| 70 | } |
| 71 | return &Client{ |
| 72 | id: clientID.String(), |
| 73 | conn: conn, |
| 74 | ctx: ctx, |
| 75 | userID: user, |
| 76 | passwordGeneration: generation, |
| 77 | consumer: consumer, |
| 78 | }, nil |
| 79 | } |
| 80 | |
| 81 | type Client struct { |
| 82 | id string |
nothing calls this directly
no test coverage detected