title: Why wont a map inside of a struct accept an assignment
body: <pre><code>type DateData struct {
      Count     int
      Districts map[string]int
  }
  </code></pre>
  <p>This is the struct that I am having issues with.</p>
  <pre><code>var dates = make(map[string]DateData)
  </code></pre>
  <p>and this is how I am initialing and using said struct</p>
  <p>Why do I get an error of <code> panic: assignment to entry in nil map</code></p>
  <p>when I try to assigning a value to the districts map like so: dates[&quot;1/1/06&quot;].Districts[&quot;1&quot;] = 1
  I am not able to assign a value to the Districts field</p>
  <p>Here is the full code for context :</p>
  <pre><code>package main
  
  import (
      &quot;encoding/csv&quot;
      &quot;fmt&quot;
      &quot;io&quot;
      &quot;log&quot;
      &quot;os&quot;
      &quot;strings&quot;
  )
  
  type Report struct {
      Date      string `json:&quot;date&quot;`
      Address   string `json:&quot;address&quot;`
      District  string `json:&quot;district&quot;`
      Beat      string `json:&quot;beat&quot;`
      Grid      string `json:&quot;grid&quot;`
      Crimedesc string `json:&quot;crimedesc&quot;`
      UCRCode   string `json:&quot;ucr_ncic_code&quot;`
      Lat       string `json:&quot;latitude&quot;`
      Lon       string `json:&quot;longitude&quot;`
  }
  
  type DateData struct {
      Count     int
      Districts map[string]int
  }
  
  func main() {
  
      reports := CreateReport()
  
      var dates = make(map[string]DateData)
  
      for _, report := range reports {
  
          dateIndex := strings.LastIndex(report.Date, &quot;/&quot;)
          date := report.Date[0 : dateIndex+3]
  
          val, ok := dates[date]
          if !ok {
              dates[date] = DateData{
                  Count: 1,
              }
  
          } else {
              val.Count += 1
              dates[date] = val
          }
  
      }
  
      dates[&quot;1/1/06&quot;].Districts[&quot;1&quot;] = 1
  
      fmt.Println(&quot;dates slice&quot;, dates)
      // fmt.Println(&quot;dates slice&quot;, dates)
  
  }
  
  func CreateReport() []Report {
      // csvFile, err := os.Open(&quot;./files/sacramento-jan-2006.csv&quot;)
      csvFile, err := os.Open(&quot;./files/sacramento-test.csv&quot;)
      if err != nil {
          log.Fatal(&quot;error opeining file&quot;, err)
      }
  
      defer csvFile.Close()
  
      reader := csv.NewReader(csvFile)
      var reports []Report
  
      for {
          line, err := reader.Read()
          if err == io.EOF {
              break
          } else if err != nil {
              log.Fatal(&quot;error reading file&quot;, err)
          }
  
          reports = append(reports, Report{
              Date:      line[0],
              Address:   line[1],
              District:  line[2],
              Beat:      line[3],
              Grid:      line[4],
              Crimedesc: line[5],
              UCRCode:   line[6],
              Lat:       line[7],
              Lon:       line[8],
          })
  
      }
  
      return reports
  }
  
  
  </code></pre>