Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add InitWithClient and deprecate InitClient because we don't want to copy Client's field sync.RWMutex by value #273

Merged
merged 9 commits into from
Jun 5, 2019
12 changes: 11 additions & 1 deletion proxy/proxy/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (
const port = 3307

var dialClient struct {
// This client is initialized in Init/InitClient/InitDefault and read in Dial.
// This client is initialized in Init/InitWithClient/InitDefault
// and read in Dial.
c *Client
sync.Mutex
}
Expand Down Expand Up @@ -80,12 +81,21 @@ func Init(auth *http.Client, connset *ConnSet, dialer Dialer) {

// InitClient is similar to Init, but allows you to specify the Client
// directly.

// Deprecated: Use InitWithClient instead.
func InitClient(c Client) {
dialClient.Lock()
dialClient.c = &c
dialClient.Unlock()
}

// InitWithClient specifies the Client directly.
func InitWithClient(c *Client) {
dialClient.Lock()
dialClient.c = c
dialClient.Unlock()
}

// InitDefault attempts to initialize the Dial function using application
// default credentials.
func InitDefault(ctx context.Context) error {
Expand Down