Commit 34ccf56d authored by AlexStocks's avatar AlexStocks

check parameters

parent 35056ac3
......@@ -113,8 +113,8 @@ func NewUDPClient(connNum int, connInterval time.Duration, serverAddr string) *C
// @connInterval is reconnect sleep interval when getty fails to connect the server.
// @serverAddr is server address. its prefix should be "ws://".
func NewWSClient(connNum int, connInterval time.Duration, serverAddr string) *Client {
if connNum <= 0 {
connNum = 1
if connNum <= 0 || serverAddr == "" {
panic(fmt.Sprintf("@connNum:%d, @serverAddr:%s", connNum, serverAddr))
}
if connInterval < defaultInterval {
connInterval = defaultInterval
......@@ -142,6 +142,9 @@ func NewWSClient(connNum int, connInterval time.Duration, serverAddr string) *Cl
// @privateKey is client private key(contains its public key). it can be empty.
// @caCert is the root certificate file to verify the legitimacy of server
func NewWSSClient(connNum int, connInterval time.Duration, serverAddr string, cert string) *Client {
if connNum <= 0 || serverAddr == "" || cert == "" {
panic(fmt.Sprintf("@connNum:%d, @serverAddr:%s, @cert:%s", connNum, serverAddr, cert))
}
if connNum <= 0 {
connNum = 1
......
......@@ -57,6 +57,10 @@ type Server struct {
// NewTCServer builds a tcp server.
// @addr server listen address.
func NewTCPServer(addr string) *Server {
if addr == "" {
panic(fmt.Sprintf("@addr:%s", addr))
}
return &Server{
endPointType: TCP_SERVER,
done: make(chan gxsync.Empty),
......@@ -67,6 +71,10 @@ func NewTCPServer(addr string) *Server {
// NewUDPServer builds a unconnected udp server.
// @addr server listen address.
func NewUDPPServer(addr string) *Server {
if addr == "" {
panic(fmt.Sprintf("@addr:%s", addr))
}
return &Server{
endPointType: UDP_SERVER,
done: make(chan gxsync.Empty),
......@@ -78,6 +86,10 @@ func NewUDPPServer(addr string) *Server {
// @addr server listen address.
// @path: websocket request url path
func NewWSServer(addr string, path string) *Server {
if addr == "" {
panic(fmt.Sprintf("@addr:%s", addr))
}
return &Server{
endPointType: WS_SERVER,
done: make(chan gxsync.Empty),
......@@ -93,6 +105,10 @@ func NewWSServer(addr string, path string) *Server {
// @privateKey: server private key(contains its public key)
// @caCert: root certificate file. to verify the legitimacy of client. it can be nil.
func NewWSSServer(addr, path, cert, privateKey, caCert string) *Server {
if addr == "" || cert == "" || privateKey == "" || caCert == "" {
panic(fmt.Sprintf("@addr:%s, @cert:%s, @privateKey:%s, @caCert:%s", addr, cert, privateKey, caCert))
}
return &Server{
endPointType: WSS_SERVER,
done: make(chan gxsync.Empty),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment