title: How to write DRY and effective if-statement in golang?
body: <p>I have following code:</p>
  
  <pre><code>func main() {
      // counts := make(map[string]int)
      files := os.Args[1:]
      if len(files) == 0 {
          counts := make(map[string]int)
          countLines(os.Stdin, counts)
          fmt.Println("os.Stdin")
          printCounts(counts)
      } else {
          for _, arg := range files {
              counts := make(map[string]int)
  
              f, err := os.Open(arg)
              if err != nil {
                  fmt.Fprintf(os.Stderr, "dup2: %v\n", err)
                  continue
              }
              countLines(f, counts)
              f.Close()
              // print counts of each file
              printCounts(counts)
          }
      }
  }
  func printCounts(counts map[string]int) {
      //...
  }
  func countLines(f *os.File, counts map[string]int){
      //...
  }
  </code></pre>
  
  <p>where i repeat myself in if-else statement by initiating counts dict twice,
  (<code>counts := make(map[string]int)</code>) both in if and else.</p>
  
  <p>My question is what is the gopher-way of writing this?</p>
  
  <p>Is that better to do the allocation outside the if-else statment with <code>new</code> and do initiation in every block?</p>