title: Same algorithm, multiple input and output type possibility in Go?
body: <p>I'm currently using <a href="https://github.com/llgcode/draw2d" rel="nofollow noreferrer">draw2d</a> lib to render some image. I noticed the core algorithm and method are the same for building <a href="https://github.com/llgcode/draw2d/tree/master/draw2dsvg" rel="nofollow noreferrer">SVG</a>, or <a href="https://github.com/llgcode/draw2d/tree/master/draw2dimg" rel="nofollow noreferrer">PNG</a> images.</p>
  
  <p>I do need to render this images as SVG (for web use) and PNG (for PDF use)</p>
  
  <p>The only difference is at the entry type and output.</p>
  
  <p>for PNG rendering I've </p>
  
  <p>as input:</p>
  
  <pre><code>var gc *draw2dimg.GraphicContext
  var img *image.RGBA
  
  img = image.NewRGBA(image.Rect(0, 0, xSize, ySize))
  gc = draw2dimg.NewGraphicContext(img)
  </code></pre>
  
  <p>as output: </p>
  
  <pre><code>draw2dimg.SaveToPngFile(FileName, img)
  </code></pre>
  
  <p>and for SVG I've:</p>
  
  <p>as input:</p>
  
  <pre><code>var gc *draw2dsvg.GraphicContext
  var img *draw2dsvg.Svg
  
  img = draw2dsvg.NewSvg()
  gc = draw2dsvg.NewGraphicContext(img)
  </code></pre>
  
  <p>as output:</p>
  
  <pre><code>draw2dsvg.SaveToSvgFile(FileName, img)
  </code></pre>
  
  <p>between input and output I've the same implementation. </p>
  
  <p>Is there any way in Go to use different input type and get the same implementation without have to duplicate some code?</p>