-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
59 lines (48 loc) · 1.01 KB
/
example_test.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
50
51
52
53
54
55
56
57
58
59
package stream_test
import (
"context"
"fmt"
"github.com/sokool/stream"
"github.com/sokool/stream/example/chat/threads"
)
func ExampleAggregate_Run() {
id, _ := stream.NewID[threads.Thread]("k8Duq81o")
chat, err := stream.NewAggregate(id, threads.New, threads.Events)
if err != nil {
return
}
fmt.Println(chat)
if err = chat.Run(func(t *threads.Thread) error { return t.Start("elo", "dood") }); err != nil {
return
}
fmt.Println(chat)
if _, err = chat.WriteTo(stream.MemoryEventStore); err != nil {
return
}
fmt.Println(chat)
// Output:
// 049fab7a.Thread
// 049fab7a.Thread->2
// 049fab7a.Thread#2
}
type Person struct {
}
func (p *Person) ID() string {
//TODO implement me
return ""
}
func (p *Person) Grant(r ...stream.Role) error {
for i := range r {
fmt.Println(r[i])
}
return nil
}
func (p *Person) IsGranted(resource ...stream.Resource) error {
for i := range resource {
fmt.Println(resource[i])
}
return nil
}
func (p *Person) Context() stream.Context {
return context.TODO()
}