Skip to content

Commit

Permalink
Move error handling to the top of Parse()
Browse files Browse the repository at this point in the history
  • Loading branch information
ayang64 committed Nov 27, 2017
1 parent 96398f8 commit 720659f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions adstxt.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,16 @@ func (a *AdsTxt) parseVariable(line string) error {
// Parse parses the supplied adx.txt data and returns a packed AdsTxt
// structure.
func Parse(srcurl, txt string) (AdsTxt, error) {
if txt == "" {
return rc, fmt.Errorf("given an empty string; nothing to parse")
}

rc := AdsTxt{
Source: srcurl,
Variable: make(map[string][]string),
}

if txt == "" {
return rc, fmt.Errorf("given an empty string; nothing to parse")
}

// create a scanner that reads line by line.

for scanner := bufio.NewScanner(strings.NewReader(txt)); scanner.Scan(); {
line := strings.TrimSpace(scanner.Text())

Expand Down

0 comments on commit 720659f

Please sign in to comment.