github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edge/pkg/edgehub/clients/factory.go (about) 1 package clients 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/kubeedge/kubeedge/edge/pkg/edgehub/clients/quicclient" 8 "github.com/kubeedge/kubeedge/edge/pkg/edgehub/clients/wsclient" 9 "github.com/kubeedge/kubeedge/edge/pkg/edgehub/config" 10 ) 11 12 //constant for reference to web socket of client 13 const ( 14 ClientTypeWebSocket = "websocket" 15 ClientTypeQuic = "quic" 16 ) 17 18 //GetClient returns an Adapter object with new web socket 19 func GetClient() (Adapter, error) { 20 config := config.Config 21 switch { 22 case config.WebSocket.Enable: 23 websocketConf := wsclient.WebSocketConfig{ 24 URL: config.WebSocketURL, 25 CertFilePath: config.TLSCertFile, 26 KeyFilePath: config.TLSPrivateKeyFile, 27 HandshakeTimeout: time.Duration(config.WebSocket.HandshakeTimeout) * time.Second, 28 ReadDeadline: time.Duration(config.WebSocket.ReadDeadline) * time.Second, 29 WriteDeadline: time.Duration(config.WebSocket.WriteDeadline) * time.Second, 30 ProjectID: config.ProjectID, 31 NodeID: config.NodeName, 32 } 33 return wsclient.NewWebSocketClient(&websocketConf), nil 34 case config.Quic.Enable: 35 quicConfig := quicclient.QuicConfig{ 36 Addr: config.Quic.Server, 37 CaFilePath: config.TLSCAFile, 38 CertFilePath: config.TLSCertFile, 39 KeyFilePath: config.TLSPrivateKeyFile, 40 HandshakeTimeout: time.Duration(config.Quic.HandshakeTimeout) * time.Second, 41 ReadDeadline: time.Duration(config.Quic.ReadDeadline) * time.Second, 42 WriteDeadline: time.Duration(config.Quic.WriteDeadline) * time.Second, 43 ProjectID: config.ProjectID, 44 NodeID: config.NodeName, 45 } 46 return quicclient.NewQuicClient(&quicConfig), nil 47 } 48 49 return nil, fmt.Errorf("Websocket and Quic are both disabled") 50 }