forked from golang-migrate/migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- registering method receiver directly for the driver
- currently each driver contains only a single method receiver: - enforcing method receiver pre-registration on go methods driver initialization - Method receiver name can be removed from files format - passing the DbName parameter inside the method receiver for the go methods driver
- Loading branch information
1 parent
570e4b4
commit 866ff82
Showing
6 changed files
with
116 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,39 @@ | ||
package gomethods | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dimag-jfrog/migrate/driver" | ||
"sync" | ||
) | ||
|
||
var methodsReceiversMu sync.Mutex | ||
var methodsReceivers = make(map[string]interface{}) | ||
|
||
// Registers a methods receiver object so it can be created from its name. Users of gomethods migration drivers should | ||
// call this method to register objects with their migration methods before executing the migration | ||
func RegisterMethodsReceiver(name string, receiver interface{}) { | ||
// Registers a methods receiver for go methods driver | ||
// Users of gomethods migration drivers should call this method | ||
// to register objects with their migration methods before executing the migration | ||
func RegisterMethodsReceiverForDriver(driverName string, receiver interface{}) { | ||
methodsReceiversMu.Lock() | ||
defer methodsReceiversMu.Unlock() | ||
if receiver == nil { | ||
panic("Go methods: Register receiver object is nil") | ||
} | ||
if _, dup := methodsReceivers[name]; dup { | ||
panic("Go methods: Register called twice for receiver " + name) | ||
|
||
driver := driver.GetDriver(driverName) | ||
if driver == nil { | ||
panic("Go methods: Trying to register receiver for not registered driver " + driverName) | ||
} | ||
methodsReceivers[name] = receiver | ||
} | ||
|
||
// Retrieves a registered driver by name | ||
func GetMethodsReceiver(name string) interface{} { | ||
methodsReceiversMu.Lock() | ||
defer methodsReceiversMu.Unlock() | ||
receiver := methodsReceivers[name] | ||
return receiver | ||
methodsDriver, ok := driver.(GoMethodsDriver) | ||
if !ok { | ||
panic("Go methods: Trying to register receiver for non go methods driver " + driverName) | ||
} | ||
|
||
if methodsDriver.MethodsReceiver() != nil { | ||
panic("Go methods: Methods receiver already registered for driver " + driverName) | ||
} | ||
|
||
if err := methodsDriver.SetMethodsReceiver(receiver); err != nil { | ||
panic(fmt.Sprintf("Go methods: Failed to set methods receiver for driver %s\nError: %v", | ||
driverName, err)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.