diff --git a/cfg/cfg.go b/cfg/cfg.go index 44dcd11..c053ef8 100644 --- a/cfg/cfg.go +++ b/cfg/cfg.go @@ -2,17 +2,19 @@ package cfg import ( "log" + "time" "github.com/joho/godotenv" "github.com/kelseyhightower/envconfig" ) type Config struct { - Page string `required:"true" split_words:"true"` - AdminUser string `required:"true" split_words:"true"` - Password string `required:"true" split_words:"true"` - LogFile bool `required:"true" split_words:"true"` - Bin string `required:"true" split_words:"true"` + Page string `required:"true" split_words:"true"` + AdminUser string `required:"true" split_words:"true"` + Password string `required:"true" split_words:"true"` + LogFile bool `required:"true" split_words:"true"` + Bin string `required:"true" split_words:"true"` + SubmitDelay time.Duration `default:"7500" required:"false" split_words:"true"` } func NewConfig(envFilePath string) *Config { diff --git a/internal/providers/archer_ax50.go b/internal/providers/archer_ax50.go index 047de98..43fb74d 100644 --- a/internal/providers/archer_ax50.go +++ b/internal/providers/archer_ax50.go @@ -5,6 +5,7 @@ import ( "log" "time" + "gitea.urkob.com/urko/go-wifi-switcher/pkg/provider" "github.com/go-rod/rod" ) @@ -56,7 +57,7 @@ func (p ArcherAx50) Login(user, pass string) error { return nil } -func (p ArcherAx50) SwitchWIFI() error { +func (p ArcherAx50) SwitchWIFI(cfg provider.SwitchConfig) error { pageURL := p.page.MustInfo().URL log.Println("p.page.MustInfo().URL", pageURL) @@ -94,7 +95,7 @@ func (p ArcherAx50) SwitchWIFI() error { saveButton.MustClick() log.Println(p.saveButtonID, "DONE") - time.Sleep(time.Millisecond * 7500) + time.Sleep(time.Millisecond * cfg.SubmitDelay) return nil } diff --git a/internal/providers/huawei.go b/internal/providers/huawei.go index e481f78..2bcbceb 100644 --- a/internal/providers/huawei.go +++ b/internal/providers/huawei.go @@ -5,6 +5,7 @@ import ( "log" "time" + "gitea.urkob.com/urko/go-wifi-switcher/pkg/provider" "github.com/go-rod/rod" ) @@ -66,7 +67,7 @@ func (p Huawei) Login(user, pass string) error { return nil } -func (p Huawei) SwitchWIFI() error { +func (p Huawei) SwitchWIFI(cfg provider.SwitchConfig) error { net, err := p.page.Element(p.netID) if err != nil { return fmt.Errorf("page.Element %s: %s", p.netID, err) diff --git a/internal/providers/nucom.go b/internal/providers/nucom.go index 41412fe..4c510ff 100644 --- a/internal/providers/nucom.go +++ b/internal/providers/nucom.go @@ -5,6 +5,7 @@ import ( "log" "time" + "gitea.urkob.com/urko/go-wifi-switcher/pkg/provider" "github.com/go-rod/rod" ) @@ -62,7 +63,7 @@ func (p Nucom) Login(user, pass string) error { return nil } -func (p Nucom) SwitchWIFI() error { +func (p Nucom) SwitchWIFI(cfg provider.SwitchConfig) error { wirelessMenu, err := p.page.Element(`a[id="` + p.wirelessTabID + `"]`) if err != nil { return fmt.Errorf("page.Element %s: %s", p.wirelessTabID, err) diff --git a/internal/switcher/switcher.go b/internal/switcher/switcher.go index 545ff9e..a1a3ece 100644 --- a/internal/switcher/switcher.go +++ b/internal/switcher/switcher.go @@ -37,7 +37,11 @@ func (s Switcher) SwitchWIFI(prv provider.ProviderIface) error { return fmt.Errorf("prv.Login %w", err) } - if err := prv.SwitchWIFI(); err != nil { + switchConfig := provider.SwitchConfig{ + SubmitDelay: s.config.SubmitDelay, + } + + if err := prv.SwitchWIFI(switchConfig); err != nil { return fmt.Errorf("prv.SwitchWIFI %w", err) } diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index 0c394e5..59f8051 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -1,6 +1,12 @@ package provider +import "time" + type ProviderIface interface { - Login(user, pass string) error - SwitchWIFI() error + Login(string, string) error + SwitchWIFI(SwitchConfig) error +} + +type SwitchConfig struct { + SubmitDelay time.Duration }