package main import ( "fmt" "io" "net/http" "net/url" "os" ) type NameCheap struct{} func (nc NameCheap) IPSet(reqs []IPSetRequest) error { for _, req := range reqs { if err := nc.SetSingle(req); err != nil { return fmt.Errorf("%s: %w", req.Domain, err) } } return nil } func (NameCheap) SetSingle(req IPSetRequest) error { params := url.Values{} params.Add("host", req.Host) params.Add("domain", req.Domain) params.Add("password", req.Password) params.Add("ip", req.IP) resp, err := http.Get(fmt.Sprintf("%s%s", baseURL, params.Encode())) if err != nil { return fmt.Errorf("request: %w", err) } defer resp.Body.Close() data, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("read body: %w", err) } if resp.StatusCode != http.StatusOK { fmt.Fprintf(os.Stderr, "got status [%d]: %s\n", resp.StatusCode, string(data)) } return nil }