title: How can I trim whitespaces in Go from a slice after Split
body: <p>I have a string that is comma separated, so it could be
  <code>test1, test2, test3</code> or <code>test1,test2,test3</code> or <code>test1,     test2,  test3</code>.</p>
  
  <p>I split this in Go currently with <code>strings.Split(s, ",")</code>, but now I have a <code>[]string</code> that can contain elements with an arbitrary numbers of whitespaces.</p>
  
  <p>How can I easily trim them off? What is best practice here?</p>
  
  <p>This is my current code</p>
  
  <pre><code>var property= os.Getenv(env.templateDirectories)
  if property != "" {
      var dirs = strings.Split(property, ",")
      for index,ele := range dirs {
          dirs[index] = strings.TrimSpace(ele)
      }
      return dirs
  }
  </code></pre>
  
  <p>I come from Java and assumed that there is a map/reduce etc functionality in Go also, therefore the question.</p>