package switcher import ( "fmt" "gitea.urkob.com/urko/go-wifi-switcher/cfg" "gitea.urkob.com/urko/go-wifi-switcher/pkg/provider" "github.com/go-rod/rod" ) type Switcher struct { Browser *rod.Browser Page *rod.Page config *cfg.Config } func NewSwitcher(remoteControlBrowserUrl string, config *cfg.Config) Switcher { browser := rod.New(). ControlURL(remoteControlBrowserUrl). MustConnect(). MustIgnoreCertErrors(true) page := browser.MustPage(config.Page) return Switcher{ Browser: browser, Page: page, config: config, } } func (s Switcher) SwitchWIFI(prv provider.ProviderIface) error { defer s.Browser.MustClose() defer s.Page.Close() if err := prv.Login(s.config.AdminUser, s.config.Password); err != nil { return fmt.Errorf("prv.Login %w", err) } if err := prv.SwitchWIFI(); err != nil { return fmt.Errorf("prv.SwitchWIFI %w", err) } return nil }