add Get method to the persistence service facade

This commit is contained in:
c9s 2021-02-21 16:55:45 +08:00
parent 21b092037e
commit a8516edb98
2 changed files with 15 additions and 6 deletions

View File

@ -536,12 +536,6 @@ func getSessionSymbols(session *ExchangeSession, defaultSymbols ...string) ([]st
}
func (environ *Environment) ConfigureNotificationSystem(userConfig *Config) error {
// Configure persistence service, by default we will use memory service
var persistence service.PersistenceService = environ.PersistenceServiceFacade.Memory
if environ.PersistenceServiceFacade.Redis != nil {
persistence = environ.PersistenceServiceFacade.Redis
}
environ.Notifiability = Notifiability{
SymbolChannelRouter: NewPatternChannelRouter(nil),
SessionChannelRouter: NewPatternChannelRouter(nil),
@ -562,6 +556,7 @@ func (environ *Environment) ConfigureNotificationSystem(userConfig *Config) erro
}
}
persistence := environ.PersistenceServiceFacade.Get()
telegramBotToken := viper.GetString("telegram-bot-token")
if len(telegramBotToken) > 0 {
tt := strings.Split(telegramBotToken, ":")

View File

@ -5,3 +5,17 @@ type PersistenceServiceFacade struct {
Json *JsonPersistenceService
Memory *MemoryService
}
// Get returns the preferred persistence service by fallbacks
// Redis will be preferred at the first position.
func (facade *PersistenceServiceFacade) Get() PersistenceService {
if facade.Redis != nil {
return facade.Redis
}
if facade.Json != nil {
return facade.Json
}
return facade.Memory
}