53 lines
971 B
Go
53 lines
971 B
Go
package examples
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"google.golang.org/grpc/metadata"
|
|
|
|
google "google.golang.org/grpc"
|
|
"src.dualinventive.com/go/authentication-service/grpc"
|
|
)
|
|
|
|
func ExampleGRPC() { //nolint: vet
|
|
conn, err := google.Dial("localhost:8098", google.WithInsecure())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
client := grpc.NewAuthenticationServiceClient(conn)
|
|
|
|
// Login
|
|
md := metadata.Pairs(
|
|
"userAgent", "some-user-agent",
|
|
)
|
|
ctx := metadata.NewOutgoingContext(context.Background(), md)
|
|
in := &grpc.LoginRequest{
|
|
Credentials: &grpc.Credentials{
|
|
Username: "Superuser",
|
|
CompanyCode: "ditst",
|
|
Password: "Dualsu1",
|
|
},
|
|
}
|
|
|
|
loginResp, err := client.Login(ctx, in)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
token := loginResp.Token.Secret
|
|
fmt.Println(token)
|
|
|
|
// Logout
|
|
md = metadata.Pairs(
|
|
"token", token,
|
|
)
|
|
ctx = metadata.NewOutgoingContext(context.Background(), md)
|
|
|
|
_, err = client.Logout(ctx, &grpc.Empty{})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|