Go Best Practices

Accept Interfaces, return types http://idiomaticgo.com/post/best-practice/accept-interfaces-return-structs/

Returning interfaces instead of returning a type makes consumers of our API more flexible. Take the example below, we can do any type of scan instructions as long as the type we work with contains a Scan(). The flexibility is also obvious when testing.

type scanner interface {
  Scan() error
}

func scanAccount(s scanner) error {
  var a Account
  return s.Scan(&a.ID)
}

// vs 

func scanAccount(r *sql.Rows) error {
  var a Account
  return r.Scan(&a.ID)
}