-
Notifications
You must be signed in to change notification settings - Fork 1
/
messaging.go
49 lines (35 loc) · 1.01 KB
/
messaging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package pass1
import (
"fmt"
"github.com/taubyte/tcc/object"
"github.com/taubyte/tcc/taubyte/v1/utils"
)
type messaging struct{}
func Messaging() object.Transformer[object.Refrence] {
return &messaging{}
}
func (a *messaging) Process(ct object.Context, o object.Object[object.Refrence]) (object.Object[object.Refrence], error) {
os, err := o.Child("messaging").Object()
if err != nil {
if err == object.ErrNotExist {
return o, nil
}
return nil, fmt.Errorf("fetching messaging failed with %w", err)
}
for _, ch := range os.Children() {
sel := os.Child(ch)
sel.Move("websocket", "webSocket") //TODO: camel case not needed - need fixing in specs
id, err := sel.Get("id")
if err != nil {
return nil, fmt.Errorf("fetching id failed with %w", err)
}
sel.Set("name", ch)
sel.Delete("id")
sel.Rename(id.(string))
err = utils.IndexById(ct, "messaging", ch, id.(string))
if err != nil {
return nil, fmt.Errorf("indexing messaging %s failed with %w", ch, err)
}
}
return o, nil
}