Skip to content

Instantly share code, notes, and snippets.

@nosequeldeebee
Created April 14, 2018 07:08
Show Gist options
  • Save nosequeldeebee/f31ed7ea71b8cbbc9a100b8e8864f8d9 to your computer and use it in GitHub Desktop.
Save nosequeldeebee/f31ed7ea71b8cbbc9a100b8e8864f8d9 to your computer and use it in GitHub Desktop.
func readData(rw *bufio.ReadWriter) {
for {
str, err := rw.ReadString('\n')
if err != nil {
log.Fatal(err)
}
if str == "" {
return
}
if str != "\n" {
chain := make([]Block, 0)
if err := json.Unmarshal([]byte(str), &chain); err != nil {
log.Fatal(err)
}
mutex.Lock()
if len(chain) > len(Blockchain) {
Blockchain = chain
bytes, err := json.MarshalIndent(Blockchain, "", " ")
if err != nil {
log.Fatal(err)
}
// Green console color: \x1b[32m
// Reset console color: \x1b[0m
fmt.Printf("\x1b[32m%s\x1b[0m> ", string(bytes))
}
mutex.Unlock()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment