From 599c3cfe428adccca683d3903132c190aa996e6d Mon Sep 17 00:00:00 2001 From: Loweel Date: Thu, 28 Nov 2019 11:45:08 +0100 Subject: [PATCH] Better Json format --- file.go | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/file.go b/file.go index 4043553..ae3e9c5 100644 --- a/file.go +++ b/file.go @@ -9,33 +9,27 @@ import ( "time" ) -type dumpRecord struct { - Token string - LastSeen string -} - -type dumpStats struct { - Decision string - Amount int64 -} - type dumpStruct struct { - GOOD []struct { - Token string `json:"Token"` - LastSeen string `json:"LastSeen"` - } `json:"GOOD"` - BAD []struct { - Token string `json:"Token"` - LastSeen string `json:"LastSeen"` - } `json:"BAD"` - MEH []struct { - Token string `json:"Token"` - LastSeen string `json:"LastSeen"` - } `json:"MEH"` - STATS []struct { - Decision string `json:"Decision"` - Amount int64 `json:"Amount"` - } `json:"STATS"` + GOOD []GOOD `json:"GOOD"` + BAD []BAD `json:"BAD"` + MEH []MEH `json:"MEH"` + STATS []STATS `json:"STATS"` +} +type GOOD struct { + Token string `json:"Token"` + LastSeen string `json:"LastSeen"` +} +type BAD struct { + Token string `json:"Token"` + LastSeen string `json:"LastSeen"` +} +type MEH struct { + Token string `json:"Token"` + LastSeen string `json:"LastSeen"` +} +type STATS struct { + Decision string `json:"Decision"` + Amount int64 `json:"Amount"` } // WriteToFile will print any string of text to a file safely by @@ -69,7 +63,7 @@ func saveBayesToFile() { log.Println("Trying to write json file") Classifier.BAD.Range(func(key interface{}, value interface{}) bool { - var t dumpRecord + var t BAD t.Token = key.(string) t.LastSeen = time.Unix(0, value.(int64)).String() DumpJson.BAD = append(DumpJson.BAD, t) @@ -77,7 +71,7 @@ func saveBayesToFile() { }) Classifier.GOOD.Range(func(key interface{}, value interface{}) bool { - var t dumpRecord + var t GOOD t.Token = key.(string) t.LastSeen = time.Unix(0, value.(int64)).String() DumpJson.GOOD = append(DumpJson.GOOD, t) @@ -85,7 +79,7 @@ func saveBayesToFile() { }) Classifier.MEH.Range(func(key interface{}, value interface{}) bool { - var t dumpRecord + var t MEH t.Token = key.(string) t.LastSeen = time.Unix(0, value.(int64)).String() DumpJson.MEH = append(DumpJson.MEH, t) @@ -93,7 +87,7 @@ func saveBayesToFile() { }) Classifier.STATS.Range(func(key interface{}, value interface{}) bool { - var t dumpStats + var t STATS t.Decision = key.(string) t.Amount = value.(int64) DumpJson.STATS = append(DumpJson.STATS, t)