Runtime error: assignment to entry in nil map

前端 未结 4 1078
逝去的感伤
逝去的感伤 2021-01-31 12:53

I am trying to generate a map and then convert that to a yaml file like this:

uid :
      kasi:
        cn: Chaithra
        street: fkmp
      nandan:
        c         


        
4条回答
  •  借酒劲吻你
    2021-01-31 13:47

    @Makpoc already answered the question. just adding some extra info.

    Map types are reference types, like pointers or slices, and so the value of m above is nil; it doesn't point to an initialized map. A nil map behaves like an empty map when reading, but attempts to write to a nil map will cause a runtime panic; don't do that. more info about Map

提交回复
热议问题