title: A generic golang decorator (clarification needed for a gist)
body: <p>Can someone explain what is happening in this gist ? I understand the concept of decorators and how this implementation lets one create a generic decorator, but I am little lost in a few sections (commented inline). Would really appreciate if someone could break it down for me.
  Also if this isnt the best way to write a generic decorator, what is ? I am looking for a decorator that can decorate a function of type func(args...interface{}) (interface{},error) without throwing away type safety.</p>
  
  <p><a href="https://gist.github.com/saelo/4190b75724adc06b1c5a" rel="nofollow noreferrer">https://gist.github.com/saelo/4190b75724adc06b1c5a</a></p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "reflect"
  )
  
  func Decorate(impl interface{}) interface{} {
          fn := reflect.ValueOf(impl)
          //What does inner do ? What is this codeblock ?
          inner := func(in []reflect.Value) []reflect.Value { //Why does this return the same type as the parameters passed to the function ? Does this mean this decorator only works for fns with signature func (arg TypeA) TypeA and not func (arg TypeA) TypeB ?
              f := reflect.ValueOf(impl)
  
              fmt.Println("Stuff before")
              // ...
  
              ret := f.Call(in) //What does call do ? Why cant we just use f(in) ?
  
              fmt.Println("Stuff after")
              // ...
  
              return ret
          }
  
          v := reflect.MakeFunc(fn.Type(), inner)
  
          return v.Interface()
  }
  
  var Add = Decorate(
      func (a, b int) int {
          return a + b
      },
  ).(func(a, b int) int) //Is this a type assertion ?
  
  
  
  func main() {
      fmt.Println(Add(1, 2))
  }
  </code></pre>