Created
August 13, 2020 11:19
-
-
Save meetme2meat/8fdf61df3417dd283b779fec9337e5d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"encoding/json" | |
"log" | |
"os" | |
"sync" | |
) | |
var input chan []byte | |
func readJSON(path string) { | |
input = make(chan []byte, 2) | |
go Start() | |
handler, err := os.Open(path) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer handler.Close() | |
scanner := bufio.NewScanner(handler) | |
for scanner.Scan() { | |
input <- scanner.Bytes() | |
} | |
close(input) | |
} | |
func Start() { | |
var wg sync.WaitGroup | |
for i := 0; i < 2; i++ { | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
run() | |
}() | |
} | |
wg.Wait() | |
} | |
func run() { | |
for { | |
bytes, ok := <-input | |
if !ok { | |
return | |
} | |
var data map[string]interface{} | |
json.Unmarshal(bytes, &data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment