Hey. There is a reader:
func (r *GzipLineReader) ReadItem(item interface{}) error { if !r.Scanner.Scan() { return io.EOF } fmt.Println(reflect.TypeOf(item)) err := json.Unmarshal(r.Scanner.Bytes(), &item) fmt.Println(reflect.TypeOf(item)) if err != nil { return err } return nil } The structure is passed as an argument.
type ThesaurusItem struct { Id int ObjectType ObjectNodeGraphType ThesaurusId int `json:"id"` Keywords []string `json:"keywords"` Type string `json:"type"` } The scanner is associated with a file in which json `s are written line by line:
{"id":466,"type":"ΠΠ½ΠΈΠΆΠ½ΡΠΉ ΠΌΠ°Π³Π°Π·ΠΈΠ½","keywords":["ΠΊΠ½ΠΈΠ³ΠΈ","ΠΆΡΡΠ½Π°Π»Ρ","ΠΊΠ°ΡΡΡ","ΠΊΡΠΏΠΈΡΡ ΠΊΠ½ΠΈΠ³Ρ","ΠΊΠ½ΠΈΠΆΠ½ΡΠΉ","ΠΊΠ½ΠΈΠ³Π°","ΠΊΠ½ΠΈΠ³ΠΈ","ΠΊΠ½ΠΈΠ³Π΅","ΠΊΠ½ΠΈΠ³Ρ","ΠΊΠ½ΠΈΠ³ΠΎΠΉ","ΠΊΠ½ΠΈΠ³ΠΎΡ","ΠΊΠ½ΠΈΠ³","ΠΊΠ½ΠΈΠ³Π°ΠΌ","ΠΊΠ½ΠΈΠ³Π°ΠΌΠΈ","ΠΊΠ½ΠΈΠ³Π°Ρ
","ΠΆΡΡΠ½Π°Π»","ΠΆΡΡΠ½Π°Π»Π°","ΠΆΡΡΠ½Π°Π»Ρ","ΠΆΡΡΠ½Π°Π»ΠΎΠΌ","ΠΆΡΡΠ½Π°Π»Π΅","ΠΆΡΡΠ½Π°Π»Ρ","ΠΆΡΡΠ½Π°Π»ΠΎΠ²","ΠΆΡΡΠ½Π°Π»Π°ΠΌ","ΠΆΡΡΠ½Π°Π»Π°ΠΌΠΈ","ΠΆΡΡΠ½Π°Π»Π°Ρ
","ΠΊΠ°ΡΡΠ°","ΠΊΠ°ΡΡΡ","ΠΊΠ°ΡΡΠ΅","ΠΊΠ°ΡΡΡ","ΠΊΠ°ΡΡΠΎΠΉ","ΠΊΠ°ΡΡΠΎΡ","ΠΊΠ°ΡΡ","ΠΊΠ°ΡΡΠ°ΠΌ","ΠΊΠ°ΡΡΠ°ΠΌΠΈ","ΠΊΠ°ΡΡΠ°Ρ
","ΠΊΠ½ΠΈΠΆΠ½ΡΠΉ","ΠΊΠ½ΠΈΠΆΠ½ΠΎΠ³ΠΎ","ΠΊΠ½ΠΈΠΆΠ½ΠΎΠΌΡ","ΠΊΠ½ΠΈΠΆΠ½ΡΠΌ","ΠΊΠ½ΠΈΠΆΠ½ΠΎΠΌ","ΠΊΠ½ΠΈΠΆΠ½Π°Ρ","ΠΊΠ½ΠΈΠΆΠ½ΠΎΠΉ","ΠΊΠ½ΠΈΠΆΠ½ΡΡ","ΠΊΠ½ΠΈΠΆΠ½ΠΎΡ","ΠΊΠ½ΠΈΠΆΠ½ΠΎΠ΅","ΠΊΠ½ΠΈΠΆΠ½ΡΠ΅","ΠΊΠ½ΠΈΠΆΠ½ΡΡ
","ΠΊΠ½ΠΈΠΆΠ½ΡΠΌΠΈ","ΠΊΠ½ΠΈΠΆΠ½","ΠΊΠ½ΠΈΠΆΠ½Π°","ΠΊΠ½ΠΈΠΆΠ½ΠΎ","ΠΊΠ½ΠΈΠΆΠ½Ρ"]} In the console, I have:
ThesaurusItem
map [string] interface {}
I do not understand the reasons for this behavior. Why does interface become a map? How to achieve the state in which the empty interface, after executing the Unmarshall function, will be filled with the data interface?