nezha/cmd/agent/main.go

49 lines
946 B
Go
Raw Normal View History

2019-12-05 09:36:58 -05:00
package main
import (
"context"
"log"
"google.golang.org/grpc"
2019-12-05 10:42:20 -05:00
pb "github.com/p14yground/nezha/proto"
2019-12-05 09:36:58 -05:00
)
// Auth ..
type Auth struct {
AppKey string
AppSecret string
}
// GetRequestMetadata ..
func (a *Auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
return map[string]string{"app_key": a.AppKey, "app_secret": a.AppSecret}, nil
}
// RequireTransportSecurity ..
func (a *Auth) RequireTransportSecurity() bool {
return false
}
func main() {
auth := Auth{
AppKey: "naiba",
2019-12-05 10:42:20 -05:00
AppSecret: "nbsecret",
2019-12-05 09:36:58 -05:00
}
conn, err := grpc.Dial(":5555", grpc.WithInsecure(), grpc.WithPerRPCCredentials(&auth))
if err != nil {
panic(err)
}
defer conn.Close()
2019-12-05 10:42:20 -05:00
client := pb.NewNezhaServiceClient(conn)
2019-12-05 09:36:58 -05:00
2019-12-05 10:42:20 -05:00
for i := 0; i < 3; i++ {
resp, err := client.ReportState(context.Background(), &pb.State{})
if err != nil {
log.Fatalf("client.Search err: %v", err)
}
log.Printf("resp: %s", resp)
}
2019-12-05 09:36:58 -05:00
}