12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package grpc_client
- import (
- "context"
- "git.sxidc.com/service-supports/ds-sdk/grpc_client/v1"
- "google.golang.org/grpc"
- "google.golang.org/grpc/credentials/insecure"
- )
- type Client struct {
- conn *grpc.ClientConn
- sqlServiceV1 v1.SqlServiceClient
- }
- func NewClient(address string) (*Client, error) {
- conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
- if err != nil {
- return nil, err
- }
- return &Client{
- conn: conn,
- sqlServiceV1: v1.NewSqlServiceClient(conn),
- }, nil
- }
- func Destroy(c *Client) error {
- if c == nil {
- return nil
- }
- err := c.conn.Close()
- if err != nil {
- return err
- }
- c.sqlServiceV1 = nil
- c.conn = nil
- c = nil
- return nil
- }
- func (c *Client) Transaction() (v1.SqlService_TransactionClient, error) {
- return c.sqlServiceV1.Transaction(context.Background())
- }
|