title: golang , How to count elements in struct type interface{}?
body: <p>I'm rather new in Go, but trying hard..</p>
  
  <p>I'm trying to write some logick, that need to check if an attribute of struct consists only of one element, or the first element has only one child. </p>
  
  <p>Main struct is this : </p>
  
  <pre><code>type ChartOptins struct {
      Filters Filter `json:"filters"`
      Charts interface{} `json:"charts"`
  }
  </code></pre>
  
  <p>Charts are born to be a composition of arrays of structure like this :</p>
  
  <pre><code>    $filters = array(
          "filters" =&gt; array(
              "DayStart" =&gt; "12-01-2015",
              "DayEnd" =&gt; "12-05-2015",
              "TimePeriods"=&gt; array(
                  array("qqq","www"),
              ),
              "lines" =&gt; array(
                  "first","avokado","drunduki"
              )
  
          ),
          "charts" =&gt; array(
              "noagg" =&gt; array(
                  array(
                      "name" =&gt; "HOLD",
                      "type" =&gt; "line"
                  ),
                  array(
                      "name" =&gt; "UKKR",
                      "type" =&gt; "line"
                  ),
                  array(
                      "name" =&gt; "SVO",
                      "type" =&gt; "line"
                  ),
              ),
              "oracle" =&gt; array(
                  array(
                      "name" =&gt; "TDD",
                      "type" =&gt; "line"
                  ),
              ) 
          ),
      );
  </code></pre>
  
  <p>Into the stuct <code>ChartOptions</code> I parse the JSON from POST request. JSON looks like this :</p>
  
  <pre><code>{ "filters": { "dayStart": "11-10-2015", "dayEnd": "21-10-2015", "timePeriods": [ [ "qqq", "www" ] ], "lines": [ "first", "avokado", "drunduki" ] }, "charts": { "noagg": [ { "name": "HOLD", "type": "line" } ] } }
  </code></pre>
  
  <p>So , <code>charts</code> can have only 1 source and 1 element in it, or any amount of elements in any amount of  sources. </p>
  
  <pre><code>"charts" : { "noagg": [ { "name": "HOLD", "type": "line" } ] }
  or
  "charts" : { "noagg": [ { "name": "HOLD", "type": "line" } , { "name": "TDD", "type": "line" } , { "name": "SVO", "type": "line" } ] }
  </code></pre>
  
  <p>Of cource, this is the JSON elements that comes to go script, and i parse them into interface{}. When I tried to use <code>len()</code>, Go said that I cant use it on interface.. </p>
  
  <p>What is the best practice to work with the amount of elements, and what is the best way to achieve such a check?</p>