mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 19:54:10 -06:00
28df41fd96
* Add HostName method * Add test * Fix lint
34 lines
819 B
Go
34 lines
819 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) HostName() string {
|
|
return m.Host
|
|
}
|
|
|
|
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
|
|
}
|