mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-11-10 09:12:47 +08:00
CHORE: linting (#2176)
This commit is contained in:
parent
fb6a79ab6f
commit
81054e72c5
3 changed files with 23 additions and 14 deletions
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue