Skip to content

Commit

Permalink
fix #6 and #7 and add Version
Browse files Browse the repository at this point in the history
  • Loading branch information
areYouLazy committed Feb 25, 2021
1 parent 591dda1 commit 5f5117d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions libhosty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5f5117d

Please sign in to comment.