CHORE: Satisfy Staticcheck and remove unused code (#2331)

This commit is contained in:
Daniil Lemenkov 2023-05-08 23:49:26 +03:00 committed by GitHub
parent f7118574a9
commit 36e3595612
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 43 additions and 109 deletions

View file

@ -667,7 +667,7 @@ func tlsa(name string, usage, selector, matchingtype uint8, target string) *mode
return r
}
func ns1_urlfwd(name, target string) *models.RecordConfig {
func ns1Urlfwd(name, target string) *models.RecordConfig {
return makeRec(name, target, "NS1_URLFWD")
}
@ -1700,8 +1700,8 @@ func makeTests(t *testing.T) []*TestGroup {
testgroup("NS1_URLFWD tests",
only("NS1"),
tc("Add a urlfwd", ns1_urlfwd("urlfwd1", "/ http://example.com 302 2 0")),
tc("Update a urlfwd", ns1_urlfwd("urlfwd1", "/ http://example.org 301 2 0")),
tc("Add a urlfwd", ns1Urlfwd("urlfwd1", "/ http://example.com 302 2 0")),
tc("Update a urlfwd", ns1Urlfwd("urlfwd1", "/ http://example.org 301 2 0")),
),
//// IGNORE* features

View file

@ -9,8 +9,8 @@ import (
)
const (
DOMAIN_UNIQUENAME = "dnscontrol_uniquename"
DOMAIN_TAG = "dnscontrol_tag"
DomainUniqueName = "dnscontrol_uniquename"
DomainTag = "dnscontrol_tag"
)
// DomainConfig describes a DNS domain (technically a DNS zone).
@ -19,8 +19,8 @@ type DomainConfig struct {
RegistrarName string `json:"registrar"`
DNSProviderNames map[string]int `json:"dnsProviders"`
// Metadata[DOMAIN_UNIQUENAME] // .Name + "!" + .Tag
// Metadata[DOMAIN_TAG] // split horizon tag
// Metadata[DomainUniqueName] // .Name + "!" + .Tag
// Metadata[DomainTag] // split horizon tag
Metadata map[string]string `json:"meta,omitempty"`
Records Records `json:"records"`
Nameservers []*Nameserver `json:"nameservers,omitempty"`
@ -46,12 +46,12 @@ type DomainConfig struct {
// GetSplitHorizonNames returns the domain's name, uniquename, and tag.
func (dc *DomainConfig) GetSplitHorizonNames() (name, uniquename, tag string) {
return dc.Name, dc.Metadata[DOMAIN_UNIQUENAME], dc.Metadata[DOMAIN_TAG]
return dc.Name, dc.Metadata[DomainUniqueName], dc.Metadata[DomainTag]
}
// GetUniqueName returns the domain's uniquename.
func (dc *DomainConfig) GetUniqueName() (uniquename string) {
return dc.Metadata[DOMAIN_UNIQUENAME]
return dc.Metadata[DomainUniqueName]
}
// UpdateSplitHorizonNames updates the split horizon fields
@ -75,8 +75,8 @@ func (dc *DomainConfig) UpdateSplitHorizonNames() {
if dc.Metadata == nil {
dc.Metadata = map[string]string{}
}
dc.Metadata[DOMAIN_UNIQUENAME] = unique
dc.Metadata[DOMAIN_TAG] = tag
dc.Metadata[DomainUniqueName] = unique
dc.Metadata[DomainTag] = tag
}
// Copy returns a deep copy of the DomainConfig.

View file

@ -51,18 +51,6 @@ var d11 = makeRec("labg", "NS", "10.10.10.97") // [11']
var d12 = makeRec("labh", "A", "1.2.3.4") // [12']
var testDataApexMX22bbb = makeRec("", "MX", "22 bbb")
func makeChange(v Verb, l, t string, old, new models.Records, msgs []string) Change {
c := Change{
Type: v,
Old: old,
New: new,
Msgs: msgs,
}
c.Key.NameFQDN = l
c.Key.Type = t
return c
}
func compareMsgs(t *testing.T, fnname, testname, testpart string, gotcc ChangeList, wantstring string) {
t.Helper()
gs := strings.TrimSpace(justMsgString(gotcc))

View file

@ -578,21 +578,6 @@ func checkDuplicates(records []*models.RecordConfig) (errs []error) {
return errs
}
// uniq returns the unique values in a map. The result is sorted lexigraphically.
func uniq(s []string) []string {
seen := make(map[string]struct{})
var result []string
for _, k := range s {
if _, ok := seen[k]; !ok {
seen[k] = struct{}{}
result = append(result, k)
}
}
sort.Strings(result)
return result
}
func checkRecordSetHasMultipleTTLs(records []*models.RecordConfig) (errs []error) {
// The RFCs say that all records at a particular recordset should have
// the same TTL. Most providers don't care, and if they do the

View file

@ -6,9 +6,6 @@ import (
)
func Test_RFC5322MailToBind(t *testing.T) {
type args struct {
rfc5322Mail string
}
tests := []struct {
name string
rfc5322Mail string

View file

@ -299,7 +299,7 @@ func (c *bindProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, foundR
c.zonefile = filepath.Join(c.directory,
makeFileName(c.filenameformat,
dc.Metadata[models.DOMAIN_UNIQUENAME], dc.Name, dc.Metadata[models.DOMAIN_TAG]),
dc.Metadata[models.DomainUniqueName], dc.Name, dc.Metadata[models.DomainTag]),
)
// We only change the serial number if there is a change.

View file

@ -72,15 +72,16 @@ type cloudflareProvider struct {
cfClient *cloudflare.API
}
func labelMatches(label string, matches []string) bool {
printer.Debugf("DEBUG: labelMatches(%#v, %#v)\n", label, matches)
for _, tst := range matches {
if label == tst {
return true
}
}
return false
}
// TODO(dlemenkov): remove this function after deleting all commented code referecing it
//func labelMatches(label string, matches []string) bool {
// printer.Debugf("DEBUG: labelMatches(%#v, %#v)\n", label, matches)
// for _, tst := range matches {
// if label == tst {
// return true
// }
// }
// return false
//}
// GetNameservers returns the nameservers for a domain.
func (c *cloudflareProvider) GetNameservers(domain string) ([]*models.Nameserver, error) {

View file

@ -19,8 +19,6 @@ const apiBase = "https://apis.cscglobal.com/dbs/api/v2"
// Api layer for CSC Global
type requestParams map[string]string
type errorResponse struct {
Code string `json:"code"`
Description string `json:"description"`

View file

@ -260,13 +260,15 @@ func (c *desecProvider) upsertRR(rr []resourceRecord, domain string) error {
return nil
}
func (c *desecProvider) deleteRR(domain, shortname, t string) error {
endpoint := fmt.Sprintf("/domains/%s/rrsets/%s/%s/", domain, shortname, t)
if _, _, err := c.get(endpoint, "DELETE"); err != nil {
return fmt.Errorf("failed delete RRset (deSEC): %v", err)
}
return nil
}
// Uncomment this function in case of using it
// It was commented out to satisfy `staticcheck` warnings about unused code
//func (c *desecProvider) deleteRR(domain, shortname, t string) error {
// endpoint := fmt.Sprintf("/domains/%s/rrsets/%s/%s/", domain, shortname, t)
// if _, _, err := c.get(endpoint, "DELETE"); err != nil {
// return fmt.Errorf("failed delete RRset (deSEC): %v", err)
// }
// return nil
//}
func (c *desecProvider) get(target, method string) ([]byte, *http.Response, error) {
retrycnt := 0

View file

@ -51,12 +51,14 @@ type structMemberInt struct {
func (m structMemberInt) structMember() {}
type structMemberBool struct {
Name string `xml:"name"`
Value bool `xml:"value>boolean"`
}
func (m structMemberBool) structMember() {}
// Uncomment this code in case of using it
// It was commented out to satisfy `staticcheck` warnings about unused code
//type structMemberBool struct {
// Name string `xml:"name"`
// Value bool `xml:"value>boolean"`
//}
//
//func (m structMemberBool) structMember() {}
type methodCall struct {
XMLName xml.Name `xml:"methodCall"`

View file

@ -12,13 +12,6 @@ import (
"github.com/namedotcom/go/namecom"
)
var defaultNameservers = []*models.Nameserver{
{Name: "ns1.name.com"},
{Name: "ns2.name.com"},
{Name: "ns3.name.com"},
{Name: "ns4.name.com"},
}
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
func (n *namedotcomProvider) GetZoneRecords(domain string, meta map[string]string) (models.Records, error) {
records, err := n.getRecords(domain)

View file

@ -13,9 +13,9 @@ const (
)
type netcupProvider struct {
domainIndex map[string]string
nameserversNames []string
credentials struct {
//domainIndex map[string]string
//nameserversNames []string
credentials struct {
apikey string
customernumber string
sessionID string
@ -112,20 +112,6 @@ func (api *netcupProvider) login(apikey, password, customernumber string) error
return nil
}
func (api *netcupProvider) logout() error {
data := paramLogout{
Key: api.credentials.apikey,
SessionID: api.credentials.sessionID,
CustomerNumber: api.credentials.customernumber,
}
_, err := api.get("logout", data)
if err != nil {
return fmt.Errorf("failed to logout from netcup: %s", err)
}
api.credentials.apikey, api.credentials.sessionID, api.credentials.customernumber = "", "", ""
return nil
}
func (api *netcupProvider) get(action string, params interface{}) (json.RawMessage, error) {
reqParam := request{
Action: action,

View file

@ -21,12 +21,6 @@ type paramLogin struct {
CustomerNumber string `json:"customernumber"`
}
type paramLogout struct {
Key string `json:"apikey"`
SessionID string `json:"apisessionid"`
CustomerNumber string `json:"customernumber"`
}
type paramGetRecords struct {
Key string `json:"apikey"`
SessionID string `json:"apisessionid"`

View file

@ -65,10 +65,6 @@ type Record struct {
SubDomain string `json:"subDomain,omitempty"`
}
type records struct {
recordsID []int
}
func (c *ovhProvider) fetchRecords(fqdn string) ([]*Record, error) {
var recordIds []int

View file

@ -15,7 +15,6 @@ import (
"github.com/StackExchange/dnscontrol/v3/models"
"github.com/StackExchange/dnscontrol/v3/pkg/printer"
"github.com/miekg/dns"
)
const (
@ -31,7 +30,6 @@ type RecordReply struct {
Status string `json:"status"`
UpdatedAt time.Time `json:"updated_at"`
Editable bool `json:"editable"`
rec dns.RR // Store miekg/dns
}
type zone struct {

View file

@ -72,7 +72,3 @@ func TestConversion(t *testing.T) {
}
}
}
func intPtr(v int) *int {
return &v
}

View file

@ -1,3 +1 @@
checks = ["all", "-ST1000", "-U1000"]
# U1000 is disabled due to https://github.com/dominikh/go-tools/issues/810
# TODO(tlim): When #810 is fixed, we should enable U1000.
checks = ["all", "-ST1000"]