-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi-demo.go
67 lines (63 loc) · 1.58 KB
/
api-demo.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
64
65
66
67
package main
import (
"context"
"fmt"
"log"
"google.golang.org/grpc"
"v2ray.com/core/app/proxyman/command"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/proxy/vmess"
)
const (
API_ADDRESS = "127.0.0.1"
API_PORT = 10085
INBOUND_TAG = "proxy"
LEVEL = 0
EMAIL = "[email protected]"
UUID = "2601070b-ab53-4352-a290-1d44414581ee"
ALTERID = 32
)
func addUser(c command.HandlerServiceClient) {
resp, err := c.AlterInbound(context.Background(), &command.AlterInboundRequest{
Tag: INBOUND_TAG,
Operation: serial.ToTypedMessage(&command.AddUserOperation{
User: &protocol.User{
Level: LEVEL,
Email: EMAIL,
Account: serial.ToTypedMessage(&vmess.Account{
Id: UUID,
AlterId: ALTERID,
SecuritySettings: &protocol.SecurityConfig{Type: protocol.SecurityType_AUTO},
}),
},
}),
})
if err != nil {
log.Printf("failed to call grpc command: %v", err)
} else {
log.Printf("ok: %v", resp)
}
}
func removeUser(c command.HandlerServiceClient) {
resp, err := c.AlterInbound(context.Background(), &command.AlterInboundRequest{
Tag: INBOUND_TAG,
Operation: serial.ToTypedMessage(&command.RemoveUserOperation{
Email: EMAIL,
}),
})
if err != nil {
log.Printf("failed to call grpc command: %v", err)
} else {
log.Printf("ok: %v", resp)
}
}
func main() {
cmdConn, err := grpc.Dial(fmt.Sprintf("%s:%d", API_ADDRESS, API_PORT), grpc.WithInsecure())
if err != nil {
panic(err)
}
hsClient := command.NewHandlerServiceClient(cmdConn)
addUser(hsClient)
// removeUser(hsClient)
}