forked from Aize-Public/forego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
51 lines (47 loc) · 974 Bytes
/
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
package http
import (
"github.com/ohait/forego/api"
"github.com/ohait/forego/ctx"
"github.com/ohait/forego/enc"
)
// TODO
func TestAPI[T Doable, UID any](c ctx.C, uid UID, obj T) error {
cli, err := api.NewClient(c, obj)
if err != nil {
return err
}
ser, err := api.NewServer(c, obj)
if err != nil {
return err
}
var data api.JSON
err = cli.Send(c, obj, &data)
if err != nil {
return err
}
{
data.UID, err = enc.Marshal(c, uid)
//data.UID, err = json.Marshal(uid)
if err != nil {
return ctx.NewErrorf(c, "can't marshal UID: %w", err)
}
op, err := ser.Recv(c, &data)
if err != nil {
return ctx.NewErrorf(c, "remote: %w", err)
}
err = op.Do(c)
if err != nil {
return ctx.NewErrorf(c, "remote: %w", err)
}
data.Data = nil // clear the buffer
err = ser.Send(c, op, &data)
if err != nil {
return ctx.NewErrorf(c, "remote: %w", err)
}
}
err = cli.Recv(c, &data, obj)
if err != nil {
return err
}
return nil
}