-
Notifications
You must be signed in to change notification settings - Fork 9
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
62 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,50 @@ | ||
package ha | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cashapp/blip" | ||
"sync" | ||
) | ||
|
||
type HAManagerFactory interface { | ||
Make(monitor blip.ConfigMonitor) (Manager, error) | ||
} | ||
|
||
func Register(f HAManagerFactory) error { | ||
hf.Lock() | ||
defer hf.Unlock() | ||
if hf.ha != nil { | ||
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 | ||
} | ||
|
||
type defaultFactory struct { | ||
} | ||
|
||
var f = &defaultFactory{} | ||
|
||
var hf = &haf{ | ||
Mutex: &sync.Mutex{}, | ||
ha: f, | ||
} | ||
|
||
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