mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
net.websocket: make logger configurable (#14998)
This commit is contained in:
parent
739f3cd90b
commit
1ae11b41e7
@ -36,11 +36,11 @@ pub mut:
|
|||||||
header http.Header // headers that will be passed when connecting
|
header http.Header // headers that will be passed when connecting
|
||||||
conn &net.TcpConn // underlying TCP socket connection
|
conn &net.TcpConn // underlying TCP socket connection
|
||||||
nonce_size int = 16 // size of nounce used for masking
|
nonce_size int = 16 // size of nounce used for masking
|
||||||
panic_on_callback bool // set to true of callbacks can panic
|
panic_on_callback bool // set to true of callbacks can panic
|
||||||
state State // current state of connection
|
state State // current state of connection
|
||||||
logger &log.Log // logger used to log messages
|
logger &log.Logger // logger used to log messages
|
||||||
resource_name string // name of current resource
|
resource_name string // name of current resource
|
||||||
last_pong_ut i64 // last time in unix time we got a pong message
|
last_pong_ut i64 // last time in unix time we got a pong message
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flag represents different types of headers in websocket handshake
|
// Flag represents different types of headers in websocket handshake
|
||||||
@ -79,6 +79,9 @@ pub enum OPCode {
|
|||||||
pub struct ClientOpt {
|
pub struct ClientOpt {
|
||||||
read_timeout i64 = 30 * time.second
|
read_timeout i64 = 30 * time.second
|
||||||
write_timeout i64 = 30 * time.second
|
write_timeout i64 = 30 * time.second
|
||||||
|
logger &log.Logger = &log.Logger(&log.Log{
|
||||||
|
level: .info
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// new_client instance a new websocket client
|
// new_client instance a new websocket client
|
||||||
@ -89,9 +92,7 @@ pub fn new_client(address string, opt ClientOpt) ?&Client {
|
|||||||
is_server: false
|
is_server: false
|
||||||
ssl_conn: openssl.new_ssl_conn()
|
ssl_conn: openssl.new_ssl_conn()
|
||||||
is_ssl: address.starts_with('wss')
|
is_ssl: address.starts_with('wss')
|
||||||
logger: &log.Log{
|
logger: opt.logger
|
||||||
level: .info
|
|
||||||
}
|
|
||||||
uri: uri
|
uri: uri
|
||||||
state: .closed
|
state: .closed
|
||||||
id: rand.uuid_v4()
|
id: rand.uuid_v4()
|
||||||
|
@ -9,7 +9,7 @@ import rand
|
|||||||
// Server represents a websocket server connection
|
// Server represents a websocket server connection
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
mut:
|
mut:
|
||||||
logger &log.Log // logger used to log
|
logger &log.Logger // logger used to log
|
||||||
ls &net.TcpListener // listener used to get incoming connection to socket
|
ls &net.TcpListener // listener used to get incoming connection to socket
|
||||||
accept_client_callbacks []AcceptClientFn // accept client callback functions
|
accept_client_callbacks []AcceptClientFn // accept client callback functions
|
||||||
message_callbacks []MessageEventHandler // new message callback functions
|
message_callbacks []MessageEventHandler // new message callback functions
|
||||||
@ -34,15 +34,20 @@ pub mut:
|
|||||||
client &Client
|
client &Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[params]
|
||||||
|
pub struct ServerOpt {
|
||||||
|
logger &log.Logger = &log.Logger(&log.Log{
|
||||||
|
level: .info
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// new_server instance a new websocket server on provided port and route
|
// new_server instance a new websocket server on provided port and route
|
||||||
pub fn new_server(family net.AddrFamily, port int, route string) &Server {
|
pub fn new_server(family net.AddrFamily, port int, route string, opt ServerOpt) &Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
ls: 0
|
ls: 0
|
||||||
family: family
|
family: family
|
||||||
port: port
|
port: port
|
||||||
logger: &log.Log{
|
logger: opt.logger
|
||||||
level: .info
|
|
||||||
}
|
|
||||||
state: .closed
|
state: .closed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user