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 ...@@ -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. // @connInterval is reconnect sleep interval when getty fails to connect the server.
// @serverAddr is server address. its prefix should be "ws://". // @serverAddr is server address. its prefix should be "ws://".
func NewWSClient(connNum int, connInterval time.Duration, serverAddr string) *Client { func NewWSClient(connNum int, connInterval time.Duration, serverAddr string) *Client {
if connNum <= 0 { if connNum <= 0 || serverAddr == "" {
connNum = 1 panic(fmt.Sprintf("@connNum:%d, @serverAddr:%s", connNum, serverAddr))
} }
if connInterval < defaultInterval { if connInterval < defaultInterval {
connInterval = defaultInterval connInterval = defaultInterval
...@@ -142,6 +142,9 @@ func NewWSClient(connNum int, connInterval time.Duration, serverAddr string) *Cl ...@@ -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. // @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 // @caCert is the root certificate file to verify the legitimacy of server
func NewWSSClient(connNum int, connInterval time.Duration, serverAddr string, cert string) *Client { 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 { if connNum <= 0 {
connNum = 1 connNum = 1
......
...@@ -57,6 +57,10 @@ type Server struct { ...@@ -57,6 +57,10 @@ type Server struct {
// NewTCServer builds a tcp server. // NewTCServer builds a tcp server.
// @addr server listen address. // @addr server listen address.
func NewTCPServer(addr string) *Server { func NewTCPServer(addr string) *Server {
if addr == "" {
panic(fmt.Sprintf("@addr:%s", addr))
}
return &Server{ return &Server{
endPointType: TCP_SERVER, endPointType: TCP_SERVER,
done: make(chan gxsync.Empty), done: make(chan gxsync.Empty),
...@@ -67,6 +71,10 @@ func NewTCPServer(addr string) *Server { ...@@ -67,6 +71,10 @@ func NewTCPServer(addr string) *Server {
// NewUDPServer builds a unconnected udp server. // NewUDPServer builds a unconnected udp server.
// @addr server listen address. // @addr server listen address.
func NewUDPPServer(addr string) *Server { func NewUDPPServer(addr string) *Server {
if addr == "" {
panic(fmt.Sprintf("@addr:%s", addr))
}
return &Server{ return &Server{
endPointType: UDP_SERVER, endPointType: UDP_SERVER,
done: make(chan gxsync.Empty), done: make(chan gxsync.Empty),
...@@ -78,6 +86,10 @@ func NewUDPPServer(addr string) *Server { ...@@ -78,6 +86,10 @@ func NewUDPPServer(addr string) *Server {
// @addr server listen address. // @addr server listen address.
// @path: websocket request url path // @path: websocket request url path
func NewWSServer(addr string, path string) *Server { func NewWSServer(addr string, path string) *Server {
if addr == "" {
panic(fmt.Sprintf("@addr:%s", addr))
}
return &Server{ return &Server{
endPointType: WS_SERVER, endPointType: WS_SERVER,
done: make(chan gxsync.Empty), done: make(chan gxsync.Empty),
...@@ -93,6 +105,10 @@ func NewWSServer(addr string, path string) *Server { ...@@ -93,6 +105,10 @@ func NewWSServer(addr string, path string) *Server {
// @privateKey: server private key(contains its public key) // @privateKey: server private key(contains its public key)
// @caCert: root certificate file. to verify the legitimacy of client. it can be nil. // @caCert: root certificate file. to verify the legitimacy of client. it can be nil.
func NewWSSServer(addr, path, cert, privateKey, caCert string) *Server { 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{ return &Server{
endPointType: WSS_SERVER, endPointType: WSS_SERVER,
done: make(chan gxsync.Empty), 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