title: Golang function pointer as a part of a struct
body: <p>I have the following code:</p>
  
  <pre><code>type FWriter struct {
      WriteF func(p []byte) (n int,err error)
  }
  
  func (self *FWriter) Write(p []byte) (n int, err error) {
      return self.WriteF(p)
  }
  
  func MyWriteFunction(p []byte) (n int, err error) { 
      // this function implements the Writer interface but is not named "Write"
      fmt.Print("%v",p)
      return len(p),nil
  }
  
  MyFWriter := new(FWriter)
  MyFWriter.WriteF = MyWriteFunction
  // I want to use MyWriteFunction with io.Copy
  io.Copy(MyFWriter,os.Stdin)
  </code></pre>
  
  <p>What I am trying to do is to create a Writer interface to wrap <code>MyWriteFunction</code> because it is not named "Write" and I can't use it with anything that requires a "Writer" interface.</p>
  
  <p>This code won't work as it complains:</p>
  
  <blockquote>
    <p>method MyWriterFunction is not an expression, must be called</p>
  </blockquote>
  
  <p>What am I doing wrong here? How can I set <code>WriteF</code> to be <code>MyWriteFunction</code>?</p>
  
  <p>Note: I simplified this problem as much as I can and in reality I have a struct which has <code>MyWriteFunction</code> AND a normal Write function so it gets a little bit complicated... (Also if there is a better way to solve this problem of mine then I'll be glad to hear it!)</p>
  
  <p>Thanks!!</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> I have notice my typo and fixed it (<code>MyWriterFunction</code> --> <code>MyWriteFunction</code>).</p>
  
  <p>I think I over-simplified the question in a manner that mislead you of my original intent. Following the Anonymous comment and peterSO kind comments I have re-created the error to better demonstrate my problem:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "io"
      "strings"
  )
  
  type ProxyWrite interface {
      Write(p []byte) (n int, err error)
      SpecialWrite(p []byte) (n int, err error)
  }
  
  type Implementer struct {
      counter int
  }
  
  func (self Implementer) Write(p []byte) (n int, err error) {
      fmt.Print("Normal write: %v", p)
      return len(p),nil
  }
  
  func (self Implementer) SpecialWrite(p []byte) (n int, err error) {
      fmt.Print("Normal write: %v\n", p)
      fmt.Println("And something else")
      self.counter += 1
      return len(p),nil
  }
  
  
  type WriteFunc func(p []byte) (n int, err error)
  
  func (wf WriteFunc) Write(p []byte) (n int, err error) {
      return wf(p)
  }
  
  func main() {
      Proxies := make(map[int]ProxyWrite,2)
      Proxies[1] = new(Implementer)
      Proxies[2] = new(Implementer)
  
      /* runs and uses the Write method normally */
      io.Copy(Proxies[1], strings.NewReader("Hello world"))
      /* gets ./main.go:45: method Proxies[1].SpecialWrite is not an expression, must be called */
      io.Copy(WriteFunc(Proxies[1].SpecialWrite), strings.NewReader("Hello world"))
  }
  </code></pre>
  
  <p>I hope it clarifies what I meant to present on the first attempt.</p>
  
  <p>Any thoughts?</p>