Fix lint errors
This commit is contained in:
parent
7dddc97bbc
commit
fda1488ae2
@ -30,6 +30,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
content := common.Content{
|
content := common.Content{
|
||||||
ID: uuid.NewString(),
|
ID: uuid.NewString(),
|
||||||
Data: buf,
|
Data: buf,
|
||||||
|
|||||||
@ -16,13 +16,17 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
defer func() {
|
defer func() {
|
||||||
common.PrintMemUsage()
|
common.PrintMemUsage()
|
||||||
|
|
||||||
f, err := os.Create("mem.prof")
|
f, err := os.Create("mem.prof")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Print("could not create memory profile: ", err)
|
fmt.Print("could not create memory profile: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer f.Close() // error handling omitted for example
|
defer f.Close() // error handling omitted for example
|
||||||
runtime.GC() // get up-to-date statistics
|
|
||||||
|
runtime.GC() // get up-to-date statistics
|
||||||
|
|
||||||
if err := pprof.WriteHeapProfile(f); err != nil {
|
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||||
fmt.Print("could not write memory profile: ", err)
|
fmt.Print("could not write memory profile: ", err)
|
||||||
return
|
return
|
||||||
@ -45,11 +49,11 @@ func readFile() ([]byte, error) {
|
|||||||
fmt.Printf("Error reading file: %v\n", err)
|
fmt.Printf("Error reading file: %v\n", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseData(data []byte) {
|
func parseData(data []byte) {
|
||||||
|
|
||||||
common.PrintMemUsage()
|
common.PrintMemUsage()
|
||||||
|
|
||||||
output := common.FooArray{
|
output := common.FooArray{
|
||||||
@ -64,8 +68,8 @@ func parseData(data []byte) {
|
|||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
//nolint:errcheck
|
||||||
jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
|
jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
|
||||||
|
|
||||||
e, errInner := getEntry(value)
|
e, errInner := getEntry(value)
|
||||||
if errInner != nil {
|
if errInner != nil {
|
||||||
fmt.Printf("Error decoding input2: %v\n", errInner)
|
fmt.Printf("Error decoding input2: %v\n", errInner)
|
||||||
@ -73,7 +77,6 @@ func parseData(data []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
output.Entries = append(output.Entries, e)
|
output.Entries = append(output.Entries, e)
|
||||||
|
|
||||||
}, "entries")
|
}, "entries")
|
||||||
|
|
||||||
common.PrintMemUsage()
|
common.PrintMemUsage()
|
||||||
@ -84,6 +87,7 @@ func parseData(data []byte) {
|
|||||||
func getEntry(data []byte) (*common.Foo, error) {
|
func getEntry(data []byte) (*common.Foo, error) {
|
||||||
e := &common.Foo{}
|
e := &common.Foo{}
|
||||||
|
|
||||||
|
//nolint:errcheck
|
||||||
jsonparser.ObjectEach(data, func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error {
|
jsonparser.ObjectEach(data, func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error {
|
||||||
switch string(key) {
|
switch string(key) {
|
||||||
case "id":
|
case "id":
|
||||||
@ -111,7 +115,9 @@ func getEntry(data []byte) (*common.Foo, error) {
|
|||||||
fmt.Printf("Unexpected Input: %v\n", key)
|
fmt.Printf("Unexpected Input: %v\n", key)
|
||||||
return errors.New("Unexpected Input: " + string(key))
|
return errors.New("Unexpected Input: " + string(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,9 @@ func Benchmark_parseData(b *testing.B) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
parseData(d)
|
parseData(d)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user