-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.go
63 lines (51 loc) · 1.29 KB
/
api.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
60
61
62
63
package main
import (
"context"
"uprpc/cli"
"uprpc/proto"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
type Api struct {
ctx context.Context
cli *cli.Client
}
func newApi() *Api {
return &Api{}
}
func (api *Api) startup(ctx context.Context) {
api.ctx = ctx
api.cli = cli.New(ctx)
}
type R struct {
Success bool `json:"success,omitempty"`
Message string `json:"message,omitempty"`
Data interface{} `json:"data,omitempty"`
}
func (api *Api) OpenProto() R {
return R{Success: true, Data: proto.ImportFile(api.ctx)}
}
func (api *Api) OpenIncludeDir() R {
return R{Success: true, Data: proto.OpenIncludeDir(api.ctx)}
}
func (api *Api) ParseProto(fileNames []string, includeDirs []string) R {
files, err := proto.Parse(fileNames, includeDirs)
if err != nil {
return R{Success: false, Message: err.Error()}
} else {
return R{Success: true, Data: files}
}
}
func (api *Api) Send(req cli.RequestData) R {
runtime.LogPrintf(api.ctx, "send request data: %+v", req)
api.cli.Send(&req)
return R{Success: true, Data: nil}
}
func (api *Api) Push(req cli.RequestData) R {
runtime.LogPrintf(api.ctx, "push request data: %+v", req)
api.cli.Push(&req)
return R{Success: true, Data: nil}
}
func (api *Api) Stop(id string) R {
api.cli.Stop(id)
return R{Success: true, Data: nil}
}