I am going to create a project in Go, but I want to separate my tiers. My goal is create a package that has code something like the DAO pattern, i.e. I wish that my caller should only communicate with the interface of the service (which might be another project) and not with the implementation. This is to avoid the situation of a future change to the database, the caller should not change and should be transparent to this change.
I was thinking of creating a project db that contains a file called persistence with a package persistence as well
http://play.golang.org/p/O9b93F4LJp
package persistence
// Interface that have the CRUD which I need to use from service(another project)
type Recorder interface {
Selectkey([]byte) (err error)
Insert([]byte, []byte) (err error)
Update([]byte, []byte) (err error)
Delete([]byte) (err error)
}
// Struct for Oracle
type ManageDataOracle struct {
}
// Struct for binaryTree
type ManageDataBInaryTree struct {
}
// Struct for MongoDB
type ManageDataMongoDb struct {
}
// Implemtations for Oracle
func (memory *ManageDataOracle) SelectKey(pKey []byte) error {
// Logic for Oracle Here
return nil
}
func (memory *ManageDataOracle) Insert(pKey []byte, pValue []byte) error {
// Logic for Oracle Here
return nil
}
func (memory *ManageDataOracle) Update(pKey []byte, pValue []byte) error {
// Logic for Oracle Here
return nil
}
func (memory *ManageDataOracle) Delete(pKey []byte) error {
// Logic for Oracle Here
return nil
}
// Implemtations for Binary Tree
func (memory *ManageDataBInaryTree) SelectKey(pKey []byte) error {
// Logic for Binary tree Here
return nil
}
func (memory *ManageDataBInaryTree) Insert(pKey []byte, pValue []byte) error {
// Logic for Binary tree Here
return nil
}
func (memory *ManageDataBInaryTree) Update(pKey []byte, pValue []byte) error {
// Logic for Binary tree Here
return nil
}
func (memory *ManageDataBInaryTree) Delete(pKey []byte) error {
// Logic for Binary tree Here
return nil
}
// Implemtations for Mongo DB
func (memory *ManageDataMongoDb) SelectKey(pKey []byte) error {
// Logic for MongoDB Here
return nil
}
func (memory *ManageDataMongoDb) Insert(pKey []byte, pValue []byte) error {
// Logic for MongoDB Here
return nil
}
func (memory *ManageDataMongoDb) Update(pKey []byte, pValue []byte) error {
// Logic for MongoDB Here
return nil
}
func (memory *ManageDataMongoDb) Delete(pKey []byte) error {
// Logic for MongoDB Here
return nil
}
Any advice on how to do this separation of concepts, or how the previous code should be called from another project?