Better Json format

This commit is contained in:
Loweel 2019-11-28 11:45:08 +01:00
parent e706104630
commit 599c3cfe42

54
file.go
View file

@ -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)