Refactor previous COOPGO Identity service - Initial commit
This commit is contained in:
50
examples/grpcclient/main.go
Normal file
50
examples/grpcclient/main.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("missing JSON file path")
|
||||
return
|
||||
}
|
||||
conn, err := grpc.Dial("dns:///localhost:8090", grpc.WithInsecure(), grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := grpcapi.NewMobilityAccountsClient(conn)
|
||||
|
||||
jsonFile, err := os.Open(os.Args[1])
|
||||
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
|
||||
var account storage.Account
|
||||
|
||||
json.Unmarshal(byteValue, &account)
|
||||
|
||||
accountProto := grpcapi.AccountFromStorageType(&account)
|
||||
|
||||
response, err := client.Register(context.Background(), &grpcapi.RegisterRequest{
|
||||
Account: accountProto,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
jsonresponse, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(jsonresponse))
|
||||
}
|
||||
Reference in New Issue
Block a user