@@ -11,6 +11,7 @@ import (
1111 "gopkg.in/yaml.v2"
1212)
1313
14+ // Options of the tcp server
1415type Options struct {
1516 Listen string
1617 TLS bool
@@ -21,20 +22,24 @@ type Options struct {
2122 Verbose bool
2223}
2324
25+ // TCPServer instance
2426type TCPServer struct {
2527 options Options
2628 listener net.Listener
2729}
2830
31+ // New tcp server instance with specified options
2932func New (options Options ) (* TCPServer , error ) {
3033 return & TCPServer {options : options }, nil
3134}
3235
36+ // AddRule to the server
3337func (t * TCPServer ) AddRule (rule Rule ) error {
3438 t .options .rules = append (t .options .rules , rule )
3539 return nil
3640}
3741
42+ // ListenAndServe requests
3843func (t * TCPServer ) ListenAndServe () error {
3944 listener , err := net .Listen ("tcp4" , t .options .Listen )
4045 if err != nil {
@@ -68,6 +73,7 @@ func (t *TCPServer) handleConnection(conn net.Conn) error {
6873 }
6974}
7075
76+ // ListenAndServe requests over tls
7177func (t * TCPServer ) ListenAndServeTLS () error {
7278 var tlsConfig * tls.Config
7379 if t .options .Certificate != "" && t .options .Key != "" {
@@ -108,6 +114,7 @@ func (t *TCPServer) Close() error {
108114 return t .listener .Close ()
109115}
110116
117+ // LoadTemplate from yaml
111118func (t * TCPServer ) LoadTemplate (templatePath string ) error {
112119 var config RulesConfiguration
113120 yamlFile , err := ioutil .ReadFile (templatePath )
0 commit comments