-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
61 lines (56 loc) · 1.79 KB
/
main.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
// Copyright 2024 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package main implements a client that calls the EchoError RPC on the
// echo-plugin plugin.
//
// This will parse the first arg as an error Code, and all further args will
// comprise the error message.
package main
import (
"context"
"os"
"strconv"
"strings"
pluginrpcv1 "buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go/pluginrpc/v1"
"pluginrpc.com/pluginrpc"
examplev1 "pluginrpc.com/pluginrpc/internal/example/gen/pluginrpc/example/v1"
"pluginrpc.com/pluginrpc/internal/example/gen/pluginrpc/example/v1/examplev1pluginrpc"
)
func main() {
if err := run(); err != nil {
if errString := err.Error(); errString != "" {
_, _ = os.Stderr.Write([]byte(errString + "\n"))
}
os.Exit(pluginrpc.WrapExitError(err).ExitCode())
}
}
func run() error {
client := pluginrpc.NewClient(pluginrpc.NewExecRunner("echo-plugin"))
echoServiceClient, err := examplev1pluginrpc.NewEchoServiceClient(client)
if err != nil {
return err
}
code, err := strconv.ParseInt(os.Args[1], 10, 32)
if err != nil {
return err
}
_, err = echoServiceClient.EchoError(
context.Background(),
&examplev1.EchoErrorRequest{
Code: pluginrpcv1.Code(code),
Message: strings.Join(os.Args[2:], " "),
},
)
return err
}