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.

29 lines
681 B

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