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 }