From 5f5117d05165cb3ef9579f4d192dfdaf584681a7 Mon Sep 17 00:00:00 2001 From: Emil Pandocchi Date: Thu, 25 Feb 2021 20:02:54 +0100 Subject: [PATCH] fix #6 and #7 and add Version --- libhosty.go | 3 +++ parser.go | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libhosty.go b/libhosty.go index e0b36c5..503c2cf 100644 --- a/libhosty.go +++ b/libhosty.go @@ -12,6 +12,9 @@ import ( ) const ( + //Version exposes library version + Version = "1.1" + //UNKNOWN defines unknown line type UNKNOWN = 0 //EMPTY defines empty line type diff --git a/parser.go b/parser.go index ce420c8..ba11a9d 100644 --- a/parser.go +++ b/parser.go @@ -49,7 +49,8 @@ func parser(bytesData []byte) ([]HostsFileLine, error) { // this can be a comment or a commented host line // so remove the 1st char (#), trim spaces // and try to parse the line as a host line - tmpParts := strings.Split(strings.TrimSpace(curLine.Trimed[1:]), " ") + noCommentLine := strings.TrimPrefix(curLine.Trimed, "#") + tmpParts := strings.Split(strings.TrimSpace(noCommentLine), " ") address := net.ParseIP(tmpParts[0]) // if address is nil this line is definetly a comment @@ -60,7 +61,7 @@ func parser(bytesData []byte) ([]HostsFileLine, error) { // otherwise it is a commented line so let's try to parse it as a normal line curLine.IsCommented = true - curLine.Trimed = curLine.Trimed[1:] + curLine.Trimed = noCommentLine } // not a comment or empty line so try to parse it