mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Simplify proxy dialer creation - Set new dialer on connector - Create MSSQL connector in a similar fashion to postgres * Update test * Fix lint * More lint * Use correct driver name
30 lines
752 B
Go
30 lines
752 B
Go
package mssql
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
|
|
mssql "github.com/microsoft/go-mssqldb"
|
|
"golang.org/x/net/proxy"
|
|
)
|
|
|
|
type HostTransportDialer struct {
|
|
Dialer proxy.ContextDialer
|
|
Host string
|
|
}
|
|
|
|
func (m HostTransportDialer) DialContext(ctx context.Context, network string, addr string) (conn net.Conn, err error) {
|
|
return m.Dialer.DialContext(ctx, network, addr)
|
|
}
|
|
|
|
// // we wrap the proxy.Dialer to become dialer that the mssql module accepts
|
|
func newMSSQLProxyDialer(hostName string, dialer proxy.Dialer) (mssql.Dialer, error) {
|
|
contextDialer, ok := dialer.(proxy.ContextDialer)
|
|
if !ok {
|
|
return nil, errors.New("unable to cast socks proxy dialer to context proxy dialer")
|
|
}
|
|
|
|
return &HostTransportDialer{contextDialer, hostName}, nil
|
|
}
|