@@ -11,6 +11,8 @@ import (
1111 "gopkg.in/yaml.v2"
1212)
1313
14+ const readTimeout = 5
15+
1416// Options of the tcp server
1517type Options struct {
1618 Listen string
@@ -24,12 +26,12 @@ type Options struct {
2426
2527// TCPServer instance
2628type TCPServer struct {
27- options Options
29+ options * Options
2830 listener net.Listener
2931}
3032
3133// New tcp server instance with specified options
32- func New (options Options ) (* TCPServer , error ) {
34+ func New (options * Options ) (* TCPServer , error ) {
3335 return & TCPServer {options : options }, nil
3436}
3537
@@ -50,11 +52,11 @@ func (t *TCPServer) ListenAndServe() error {
5052}
5153
5254func (t * TCPServer ) handleConnection (conn net.Conn ) error {
53- defer conn .Close ()
55+ defer conn .Close () //nolint
5456
5557 buf := make ([]byte , 4096 )
5658 for {
57- if err := conn .SetReadDeadline (time .Now ().Add (time . Duration ( 5 * time .Second ) )); err != nil {
59+ if err := conn .SetReadDeadline (time .Now ().Add (readTimeout * time .Second )); err != nil {
5860 gologger .Info ().Msgf ("%s\n " , err )
5961 }
6062 _ , err := conn .Read (buf )
@@ -77,7 +79,7 @@ func (t *TCPServer) handleConnection(conn net.Conn) error {
7779 }
7880}
7981
80- // ListenAndServe requests over tls
82+ // ListenAndServeTLS requests over tls
8183func (t * TCPServer ) ListenAndServeTLS () error {
8284 var tlsConfig * tls.Config
8385 if t .options .Certificate != "" && t .options .Key != "" {
0 commit comments