MCPcopy Create free account
hub / github.com/cloudbase/garm / NewClient

Function NewClient

websocket/client.go:54–79  ·  view source on GitHub ↗
(ctx context.Context, conn *websocket.Conn)

Source from the content-addressed store, hash-verified

52type HandleWebsocketMessage func([]byte) error
53
54func 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
81type Client struct {
82 id string

Callers

nothing calls this directly

Calls 5

UserIDFunction · 0.92
PasswordGenerationFunction · 0.92
RegisterConsumerFunction · 0.92
WithUserIDFilterFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected