Answer the question
In order to leave comments, you need to log in
Does the implementation really smell?
I have a package for working with sessions. Now they are stored in a bolt, but if I want to switch to a radish, for example, then I will need to edit the code. I made an API for robots with storage
type SessidFileDriver struct {
Get func(id string) (string, bool)
Set func(id, data string) error
Del func(id string) error
Up func(id, data string) error
}
func(SessidFileDriver)
. Sends functions to a global variable. And the second local to get functions anywhere. Then I made a driver for Bolt and in the New method I simply set the functions for working with the database. Then, if I want, I can very simply use any of the storages.
Answer the question
In order to leave comments, you need to log in
That's what interfaces are for. The wrapper over the Bolt must implement the necessary methods. Switch to Redis - write a wrapper for it.
Depending, for example, on the config, you will use one or another implementation of the interface.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question