refactor: parameterize submit delay
This commit is contained in:
parent
cc7a59c109
commit
69389d030b
12
cfg/cfg.go
12
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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue