fix(api): fix invalid platform build statements (#2064)

pull/2065/head
Anthony Lapenna 2018-07-23 16:49:04 +02:00 committed by GitHub
parent f62b40dc3f
commit b1227b17e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 40 deletions

View File

@ -0,0 +1,11 @@
// +build !windows
package websocket
import (
"net"
)
func createDial(scheme, host string) (net.Conn, error) {
return net.Dial(scheme, host)
}

View File

@ -0,0 +1,16 @@
// +build windows
package websocket
import (
"net"
"github.com/Microsoft/go-winio"
)
func createDial(scheme, host string) (net.Conn, error) {
if scheme == "npipe" {
return winio.DialPipe(host, nil)
}
return net.Dial(scheme, host)
}

View File

@ -127,7 +127,7 @@ func (handler *Handler) proxyWebsocketRequest(w http.ResponseWriter, r *http.Req
}
func hijackExecStartOperation(websocketConn *websocket.Conn, endpoint *portainer.Endpoint, execID string) error {
dial, err := createDial(endpoint)
dial, err := initDial(endpoint)
if err != nil {
return err
}
@ -158,7 +158,7 @@ func hijackExecStartOperation(websocketConn *websocket.Conn, endpoint *portainer
return nil
}
func createDial(endpoint *portainer.Endpoint) (net.Conn, error) {
func initDial(endpoint *portainer.Endpoint) (net.Conn, error) {
url, err := url.Parse(endpoint.URL)
if err != nil {
return nil, err
@ -170,26 +170,16 @@ func createDial(endpoint *portainer.Endpoint) (net.Conn, error) {
host = url.Path
}
var (
dial net.Conn
dialErr error
)
if endpoint.TLSConfig.TLS {
tlsConfig, err := crypto.CreateTLSConfigurationFromDisk(endpoint.TLSConfig.TLSCACertPath, endpoint.TLSConfig.TLSCertPath, endpoint.TLSConfig.TLSKeyPath, endpoint.TLSConfig.TLSSkipVerify)
if err != nil {
return nil, err
}
dial, dialErr = tls.Dial(url.Scheme, host, tlsConfig)
} else {
if url.Scheme == "npipe" {
dial, dialErr = createWinDial(host)
} else {
dial, dialErr = net.Dial(url.Scheme, host)
}
return tls.Dial(url.Scheme, host, tlsConfig)
}
return dial, dialErr
return createDial(url.Scheme, host)
}
func createExecStartRequest(execID string) (*http.Request, error) {

View File

@ -1,11 +0,0 @@
// +build linux
package websocket
import (
"net"
)
func createWinDial(host string) (net.Conn, error) {
return nil, nil
}

View File

@ -1,13 +0,0 @@
// +build windows
package websocket
import (
"net"
"github.com/Microsoft/go-winio"
)
func createWinDial(host string) (net.Conn, error) {
return winio.DialPipe(host, nil)
}

View File

@ -1,4 +1,4 @@
// +build linux
// +build !windows
package proxy