From 81054e72c51956f7390062cdeaba54a72d66c96b Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Wed, 15 Mar 2023 18:35:34 -0400 Subject: [PATCH] CHORE: linting (#2176) --- build/generate/functionTypes.go | 23 +++++++++++------------ pkg/diff2/compareconfig.go | 9 +++++++-- pkg/diff2/diff2.go | 5 +++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/build/generate/functionTypes.go b/build/generate/functionTypes.go index e5b75ad9d..ad508acc7 100644 --- a/build/generate/functionTypes.go +++ b/build/generate/functionTypes.go @@ -34,19 +34,18 @@ var delimiterRegex = regexp.MustCompile(`(?m)^---\n`) func parseFrontMatter(content string) (map[string]interface{}, string, error) { delimiterIndices := delimiterRegex.FindAllStringIndex(content, 2) - if len(delimiterIndices) > 0 { - startIndex := delimiterIndices[0][0] - endIndex := delimiterIndices[1][0] - yamlString := content[startIndex+4 : endIndex] - var frontMatter map[string]interface{} - err := yaml.Unmarshal([]byte(yamlString), &frontMatter) - if err != nil { - return nil, "", err - } - return frontMatter, content[endIndex+4:], nil - } else { - return nil, "", fmt.Errorf("Failed to parse file. Remove it and try again.") + if len(delimiterIndices) < 1 { + return nil, "", fmt.Errorf("failed to parse file. Remove it and try again") } + startIndex := delimiterIndices[0][0] + endIndex := delimiterIndices[1][0] + yamlString := content[startIndex+4 : endIndex] + var frontMatter map[string]interface{} + err := yaml.Unmarshal([]byte(yamlString), &frontMatter) + if err != nil { + return nil, "", err + } + return frontMatter, content[endIndex+4:], nil } var returnTypes = map[string]string{ diff --git a/pkg/diff2/compareconfig.go b/pkg/diff2/compareconfig.go index a14a773f3..faaec057c 100644 --- a/pkg/diff2/compareconfig.go +++ b/pkg/diff2/compareconfig.go @@ -43,8 +43,11 @@ differencing engine, such as maps of which labels and RecordKeys exist. */ +// ComparableFunc is a signature for functions used to generate a comparable +// blob for custom records and records with metadata. type ComparableFunc func(*models.RecordConfig) string +// CompareConfig stores a zone's records in a structure that makes comparing two zones convenient. type CompareConfig struct { // The primary data. Each record stored once, grouped by label then // by rType: @@ -88,6 +91,7 @@ type targetConfig struct { rec *models.RecordConfig // The RecordConfig itself. } +// NewCompareConfig creates a CompareConfig from a set of records and other data. func NewCompareConfig(origin string, existing, desired models.Records, compFn ComparableFunc) *CompareConfig { cc := &CompareConfig{ existing: existing, @@ -101,14 +105,15 @@ func NewCompareConfig(origin string, existing, desired models.Records, compFn Co } cc.addRecords(existing, true) // Must be called first so that CNAME manipulations happen in the correct order. cc.addRecords(desired, false) - cc.VerifyCNAMEAssertions() + cc.verifyCNAMEAssertions() sort.Slice(cc.ldata, func(i, j int) bool { return prettyzone.LabelLess(cc.ldata[i].label, cc.ldata[j].label) }) return cc } -func (cc *CompareConfig) VerifyCNAMEAssertions() { +// verifyCNAMEAssertions verifies assertions about CNAME updates ordering. +func (cc *CompareConfig) verifyCNAMEAssertions() { // According to the RFCs if a label has a CNAME, it can not have any other // records at that label... even other CNAMEs. Therefore, we need to be diff --git a/pkg/diff2/diff2.go b/pkg/diff2/diff2.go index a26ccf31b..6742f1dfb 100644 --- a/pkg/diff2/diff2.go +++ b/pkg/diff2/diff2.go @@ -13,8 +13,10 @@ import ( "github.com/StackExchange/dnscontrol/v3/models" ) +// Verb indicates the Change's type (create, delete, etc.) type Verb int +// CREATE and other verbs. const ( _ Verb = iota // Skip the first value of 0 CREATE // Create a record/recordset/label where none existed before. @@ -23,8 +25,11 @@ const ( REPORT // No change, but I have something to say! ) +// ChangeList is a list of Change type ChangeList []Change +// Change is an instruction to the provider. Generally if one properly executes +// all the changes, an "existing" zone will turn into the "desired" zone. type Change struct { Type Verb // Add, Change, Delete