title: How to get sorted list of map keys in Go?
body: <p>Let's imagine I have a map: <code>map[string]string</code>. I would like to get the list of sorted keys for this map. So I could do something like this:</p>
  
  <pre><code>func SortedMapKeys(m map[string]string) (keyList []string) {
      for key := range m {
          keyList = append(keyList, key)
      }
      sort.Strings(keyList)
      return
  }
  </code></pre>
  
  <p>Then I will have another map of type <code>map[string]bool</code>. I would like to get it's keys also. But the problem is that function SortedMapKeys accepts a <code>map[string]string</code> argument. So I need to write exactly the same function, with the only one difference - it will accept a <code>map[string]bool</code>.</p>
  
  <p>For obvious reasons it's not an option. If one day I would like to change the logic of how I get and sort my keys, I will need to track and update all these functions. Also, I will have to write the same unit tests for all these functions which actually do the same thing since their bodies are 100% equal (code duplicate).</p>
  
  <p>Is there any way to create a generic function which could accept an <code>map[string]</code> <em>of whatever</em>?</p>