Beispiel #1
0
func (p *AbstractApiProcedure) Init(s shadow.Service, a *shadow.Application) error {
	p.Application = a
	p.Service = s

	if apiService, err := a.GetService("api"); err == nil {
		if castService, ok := apiService.(*ApiService); ok {
			p.ApiService = castService
			return nil
		}
	}

	return errors.New("Api service not found")
}
Beispiel #2
0
func (s *SenderService) Init(a *shadow.Application) error {
	s.application = a

	resourceSender, err := a.GetResource("sender")
	if err != nil {
		return err
	}
	s.Sender = resourceSender.(*resource.SenderResource)

	resourceConfig, err := a.GetResource("config")
	if err != nil {
		return err
	}
	s.config = resourceConfig.(*r.Config)

	serviceFrontend, err := a.GetService("frontend")
	if err != nil {
		return err
	}
	s.FrontendService = serviceFrontend.(*frontend.FrontendService)

	resourceLogger, err := a.GetResource("logger")
	if err != nil {
		return err
	}
	s.Logger = resourceLogger.(*r.Logger).Get(s.GetName())

	resourceStorage, err := a.GetResource("database")
	if err != nil {
		return err
	}
	s.storage = resourceStorage.(*database.Database).GetStorage()

	s.storage.AddTableWithName(model.Application{}, model.TableApplications).ColMap("token").SetUnique(true)
	s.storage.AddTableWithName(model.Endpoint{}, model.TableEndpoints).ColMap("token").SetUnique(true)
	s.storage.AddTableWithName(model.Message{}, model.TableMessages)
	s.storage.AddTableWithName(model.Publish{}, model.TablePublishes)

	if err = s.storage.CreateTablesIfNotExists(); err != nil {
		return err
	}

	// provides
	s.Balances = map[string]float64{}

	if s.Sender.HasProvider("smsintel") {
		s.Balances["smsintel"] = float64(0)
	}

	return nil
}
Beispiel #3
0
func (c *AbstractSlackCommand) Init(s shadow.Service, a *shadow.Application) {
	c.Application = a
	c.Service = s

	slackService, err := a.GetService("slack")
	if err == nil {
		if castService, ok := slackService.(*SlackService); ok {
			c.SlackService = castService
			return
		}
	}

	panic("Slack service not found")
}