I'm developing a framework in Go where I let the user inject dependencies like a logger and a database. I provide interfaces for these that I expect the user to implement.
Now I also need the user to provide a bunch of functions, like signature verification and hashing, because I don't want to choose a specific implementation for it. See the following (unrealistic) example
package crypto
type Fns interface {
// Hash returns the hash digest of the passed data
Hash([]byte) []byte
// Verify checks for a valid signature on the message for given public key
Verify(msg, sig []byte, pk PublicKey) (bool, error)
}
So this crypto.Fns
interface is just a collection of functions. I expect the user to implement it as a stateless struct{}
type. I also don't want to save it to a package global variable and just wrap the calls like so
package crypto
// user must set this before using the framework
var Impl Fns
func Hash(data []byte) []byte { return Impl.Hash(data) }
// ...
because at a later point in time it might become interesting to use different implementations at different places in the framework.
Do you think this is a good pattern? If so, how should I name this thing? Fns
? Helper
? Impl
?