-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.go
50 lines (46 loc) · 1.1 KB
/
list.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
package tester
import (
"fmt"
"strings"
"github.com/shivuslr41/grpc-tester/exec"
)
// List uses grpcurl to list all available gRPC services and methods on a server, either with or without TLS.
// It returns a map of service names and their corresponding methods.
func (l *Lister) List() (map[string][]string, error) {
var server string
if l.ProtoPath != "" {
server = l.protoFlag()
} else {
server = l.Server
}
b, err := exec.NewCMD(
fmt.Sprintf(
"grpcurl %s %s list",
l.tlsFlag(),
server,
),
).CombinedOutput()
if err != nil {
return nil, fmt.Errorf("%s", string(b))
}
servicesAndMethods := make(map[string][]string)
for _, service := range removeEmptyStrings(strings.Split(string(b), "\n")) {
b, err = exec.NewCMD(
fmt.Sprintf(
"grpcurl %s %s list %s",
l.tlsFlag(),
server,
service,
),
).CombinedOutput()
if err != nil {
return nil, fmt.Errorf("%s", string(b))
}
servicesAndMethods[service] = removeEmptyStrings(strings.Split(string(b), "\n"))
}
return servicesAndMethods, nil
}
// Execute start list command
func (l *Lister) Execute() {
l.print()
}