You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
750 B

  1. package grpcdb
  2. import (
  3. "google.golang.org/grpc"
  4. "google.golang.org/grpc/credentials"
  5. protodb "github.com/tendermint/tmlibs/proto"
  6. )
  7. // Security defines how the client will talk to the gRPC server.
  8. type Security uint
  9. const (
  10. Insecure Security = iota
  11. Secure
  12. )
  13. // NewClient creates a gRPC client connected to the bound gRPC server at serverAddr.
  14. // Use kind to set the level of security to either Secure or Insecure.
  15. func NewClient(serverAddr, serverCert string) (protodb.DBClient, error) {
  16. creds, err := credentials.NewClientTLSFromFile(serverCert, "")
  17. if err != nil {
  18. return nil, err
  19. }
  20. cc, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(creds))
  21. if err != nil {
  22. return nil, err
  23. }
  24. return protodb.NewDBClient(cc), nil
  25. }