Skip to content

Instantly share code, notes, and snippets.

@robbdimitrov
Created May 2, 2020 17:50
Show Gist options
  • Save robbdimitrov/7a17e75792f07d574b5bbad1c48a345c to your computer and use it in GitHub Desktop.
Save robbdimitrov/7a17e75792f07d574b5bbad1c48a345c to your computer and use it in GitHub Desktop.
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