Created
May 2, 2020 17:50
-
-
Save robbdimitrov/7a17e75792f07d574b5bbad1c48a345c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package api | |
import ( | |
"google.golang.org/grpc" | |
) | |
// Connector holds a pool of grpc connections | |
type Connector struct { | |
connections []*grpc.ClientConn | |
} | |
// NewConnector creates a new Connector | |
func NewConnector() *Connector { | |
return &Connector{} | |
} | |
func (c *Connector) newConnection(addr string) (*grpc.ClientConn, error) { | |
conn, err := grpc.Dial(addr, grpc.WithInsecure()) | |
if err != nil { | |
return nil, err | |
} | |
c.connections = append(c.connections, conn) | |
return conn, nil | |
} | |
// Close closes all connections Connector holds | |
func (c *Connector) Close() { | |
for _, conn := range c.connections { | |
conn.Close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment