ivanzoid
9/8/2018 - 11:49 AM

Golang mysql -B output processing.go

package main

import (
	"bufio"
	"log"
	"os"
	"strings"
)

func main() {
	if len(os.Args) <= 1 {
		return
	}
	file, err := os.Open(os.Args[1])

	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	processFile(file, processLine)
}

func processFile(file *os.File, processLine func(comps []string)) error {
	scanner := bufio.NewScanner(file)
	first := true
	for scanner.Scan() {
		if first {
			first = false
			continue
		}
		line := scanner.Text()
		comps := strings.Split(line, "\t")

		processLine(comps)
	}

	if err := scanner.Err(); err != nil {
		return err
	}

	return nil
}

func processLine(comps []string) {
}