Golang return pointer to interface throws error
<p>I have a basic function in Go that opens a file and tries to decode its JSON contents.</p>

<p>I am trying to extract the default <code>json.NewDecoder()</code> function so I can easily mock this in my tests.</p>

<p>However, my implementation seems to return an error:</p>

<blockquote>
  <p>cannot use json.NewDecoder (type func(io.Reader) *json.Decoder) as type decoderFactory in argument to NewConfig</p>
</blockquote>

<p>Code:</p>

<pre><code>package main

import (
    "encoding/json"
    "fmt"
    "io"
    "os"
)

type openFile func(name string) (*os.File, error)

type decoderFactory func(r io.Reader) decoder

type decoder interface {
    Decode(v interface{}) error
}

type Config struct {
    ConsumerKey,
    ConsumerSecret,
    AccessToken,
    AccessTokenSecret string
}

func NewConfig(open openFile, d decoderFactory) (*Config, error) {
    c := new(Config)
    file, err := open("some.file")
    if err != nil {
        return nil, fmt.Errorf("error opening config file")
    }
    defer file.Close()

    decoder := d(file)
    if err := decoder.Decode(&amp;c); err != nil {
        return nil, fmt.Errorf("error decoding config JSON")
    }

    return c, nil
}

func main() {
    _, err := NewConfig(os.Open, json.NewDecoder)
    if err != nil {
        fmt.Fprintf(os.Stderr, "something bad happened: %v\n", err)
    }
}
</code></pre>

<p>Here's a link to the <a href="https://play.golang.org/p/Je1YR4AKZ1" rel="nofollow">Go playground</a></p>

<p>Where am I going wrong?</p>