Reading with a scanner

Scanner is part of the bufio package. It is useful for stepping through files at specific delimiters. Commonly, the newline character is used as the delimiter to break up a file by lines. In a CSV file, commas would be the delimiter. The os.File object can be wrapped in a bufio.Scanner object just like a buffered reader. We will call Scan() to read up to the next delimiter, and then, use Text() or Bytes() to get the data that was read.

The delimiter is not just a simple byte or character. There is actually a special function, which you have to implement, that will determine where the next delimiter is, how far forward to advance the pointer, and what data to return. If no custom SplitFunc type is provided, it defaults ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.