Files
learngo/interfaces/05-log-parser/refactor-notes/refactor-02/changes.md
2019-08-19 10:21:17 +03:00

605 B

PROBLEM

  • summarize() knows a lot about the internals of the parser.
    • coupled to the parser.

SOLUTION

  • remove: parser.go sum and domains fields

    • remove: parser.go/newParser()
    • change: parser.go/parse(p *parser) error -> parse() ([]result, error)
    • initialize: sum inside parse()
    • remove: update()
    • call: sum update in the parse()
    • collect the grouped results and return them from parser()
  • summarize(p *parser) -> summarize([]result)

  • in summarize()

    • sort.Slice
    • range over []result
  • main.go

    • just: res, err := parse()