From 86c19a743d5d468dd8b6161e0b7bcdb3b59d3ab6 Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Tue, 5 Feb 2019 16:14:02 +0100 Subject: [PATCH] upd(all): flags cleanup --- crm/flags.go | 18 ++++++++++++------ crm/repository/flags.go | 25 +++++++++++++++++++++++++ system/flags.go | 5 ++++- 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 crm/repository/flags.go diff --git a/crm/flags.go b/crm/flags.go index c6b14f2f0..706f8b4c8 100644 --- a/crm/flags.go +++ b/crm/flags.go @@ -3,15 +3,17 @@ package service import ( "github.com/pkg/errors" + "github.com/crusttech/crust/crm/repository" "github.com/crusttech/crust/internal/config" ) type ( appFlags struct { - smtp *config.SMTP - http *config.HTTP - monitor *config.Monitor - db *config.Database + smtp *config.SMTP + http *config.HTTP + monitor *config.Monitor + db *config.Database + repository *repository.Flags } ) @@ -19,7 +21,7 @@ var flags *appFlags func (c *appFlags) Validate() error { if c == nil { - return errors.New("CRM flags are not initialized, need to call Flags()") + return errors.New("Flags are not initialized, need to call Flags()") } if err := c.http.Validate(); err != nil { return err @@ -33,6 +35,9 @@ func (c *appFlags) Validate() error { if err := c.db.Validate(); err != nil { return err } + if err := c.repository.Validate(); err != nil { + return err + } return nil } @@ -41,7 +46,7 @@ func Flags(prefix ...string) { return } if len(prefix) == 0 { - panic("crm.Flags() needs prefix on first call") + panic("Flags() needs prefix on first call") } flags = &appFlags{ @@ -49,5 +54,6 @@ func Flags(prefix ...string) { new(config.HTTP).Init(prefix...), new(config.Monitor).Init(prefix...), new(config.Database).Init(prefix...), + new(repository.Flags).Init(prefix...), } } diff --git a/crm/repository/flags.go b/crm/repository/flags.go new file mode 100644 index 000000000..f170e784b --- /dev/null +++ b/crm/repository/flags.go @@ -0,0 +1,25 @@ +package repository + +import ( + _ "github.com/crusttech/crust/internal/config" +) + +type ( + Flags struct { + // No config yet + } +) + +var flags *Flags + +func (f *Flags) Validate() error { + return nil +} + +func (f *Flags) Init(prefix ...string) *Flags { + if flags != nil { + return flags + } + flags = &Flags{} + return flags +} diff --git a/system/flags.go b/system/flags.go index 2281232c0..57298982c 100644 --- a/system/flags.go +++ b/system/flags.go @@ -21,7 +21,7 @@ var flags *appFlags func (c *appFlags) Validate() error { if c == nil { - return errors.New("Flags are not initialized, need to call Flags() or FullFlags()") + return errors.New("Flags are not initialized, need to call Flags()") } if err := c.http.Validate(); err != nil { return err @@ -38,6 +38,9 @@ func (c *appFlags) Validate() error { if err := c.oidc.Validate(); err != nil { return err } + if err := c.social.Validate(); err != nil { + return err + } return nil }