MCPcopy
hub / github.com/inancgumus/learngo / parse

Function parse

26-pointers/04-log-parser-pointers/parser.go:39–61  ·  view source on GitHub ↗

parse parses a log line and returns the parsed result with an error

(p *parser, line string)

Source from the content-addressed store, hash-verified

37
38// parse parses a log line and returns the parsed result with an error
39func parse(p *parser, line string) (parsed result) {
40 if p.lerr != nil {
41 return
42 }
43
44 p.lines++
45
46 fields := strings.Fields(line)
47 if len(fields) != 2 {
48 p.lerr = fmt.Errorf("wrong input: %v (line #%d)", fields, p.lines)
49 return
50 }
51
52 parsed.domain = fields[0]
53
54 var err error
55
56 parsed.visits, err = strconv.Atoi(fields[1])
57 if parsed.visits < 0 || err != nil {
58 p.lerr = fmt.Errorf("wrong input: %q (line #%d)", fields[1], p.lines)
59 }
60 return
61}
62
63// update updates all the parsing results using the given parsing result
64func update(p *parser, parsed result) {

Callers 1

mainFunction · 0.70

Calls 1

FieldsMethod · 0.80

Tested by

no test coverage detected