-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make HAManager configurable by Blip users
- Loading branch information
Showing
3 changed files
with
64 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ha | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cashapp/blip" | ||
"sync" | ||
) | ||
|
||
type HAManagerFactory interface { | ||
Make(monitor blip.ConfigMonitor) (Manager, error) | ||
} | ||
|
||
type defaultFactory struct { | ||
} | ||
|
||
var df = &defaultFactory{} | ||
|
||
func Register(f HAManagerFactory) error { | ||
hf.Lock() | ||
defer hf.Unlock() | ||
// Check if it's different from the default factory | ||
if hf.ha != df { | ||
return fmt.Errorf("HA already registered") | ||
} | ||
hf.ha = f | ||
blip.Debug("register HA") | ||
return nil | ||
} | ||
|
||
func Make(args blip.ConfigMonitor) (Manager, error) { | ||
hf.Lock() | ||
defer hf.Unlock() | ||
if hf.ha == nil { | ||
return nil, fmt.Errorf("HA not registered") | ||
} | ||
return hf.ha.Make(args) | ||
} | ||
|
||
type haf struct { | ||
*sync.Mutex | ||
ha HAManagerFactory | ||
} | ||
|
||
var hf = &haf{ | ||
Mutex: &sync.Mutex{}, | ||
ha: df, | ||
} | ||
|
||
func (f *defaultFactory) Make(_ blip.ConfigMonitor) (Manager, error) { | ||
return Disabled, nil | ||
} |
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