Created
May 17, 2017 14:44
-
-
Save binarin/6c017e2831af391b6fdac134d6748986 to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"encoding/json" | |
"io" | |
"os" | |
"fmt" | |
) | |
func main() { | |
var reader io.Reader | |
reader, err := os.Open("/home/binarin/tmp/dp") | |
if err != nil { | |
fmt.Println("Filed to open") | |
return | |
} | |
decoder := json.NewDecoder(reader) | |
target := make([]interface{}, 0) | |
err = decoder.Decode(&target) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
os.Mkdir("slices", 0777) | |
for _, item := range target { | |
top := item.(map[string]interface{}) | |
ts := top["timestamp"].(string) | |
out, err := os.Create("slices/" + ts) | |
if err != nil { | |
fmt.Printf("Failed to create file: %s\n", err) | |
return | |
} | |
defer out.Close() | |
enc := json.NewEncoder(out) | |
enc.Encode(top["snapshot"]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment