chore: Enable `revive:enforce-map-style` rule (#16077)
This commit is contained in:
parent
7c9d5e52b0
commit
c8a30655cb
|
|
@ -262,6 +262,9 @@ linters-settings:
|
||||||
- name: early-return
|
- name: early-return
|
||||||
- name: empty-block
|
- name: empty-block
|
||||||
- name: empty-lines
|
- name: empty-lines
|
||||||
|
- name: enforce-map-style
|
||||||
|
arguments: ["make"]
|
||||||
|
exclude: [ "TEST" ]
|
||||||
- name: error-naming
|
- name: error-naming
|
||||||
- name: error-return
|
- name: error-return
|
||||||
- name: error-strings
|
- name: error-strings
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ func (op OrderedPlugins) Less(i, j int) bool { return op[i].Line < op[j].Line }
|
||||||
// once the configuration is parsed.
|
// once the configuration is parsed.
|
||||||
func NewConfig() *Config {
|
func NewConfig() *Config {
|
||||||
c := &Config{
|
c := &Config{
|
||||||
UnusedFields: map[string]bool{},
|
UnusedFields: make(map[string]bool),
|
||||||
unusedFieldsMutex: &sync.Mutex{},
|
unusedFieldsMutex: &sync.Mutex{},
|
||||||
|
|
||||||
// Agent defaults:
|
// Agent defaults:
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ func (t *Table) initBuild() error {
|
||||||
t.Name = oidText
|
t.Name = oidText
|
||||||
}
|
}
|
||||||
|
|
||||||
knownOIDs := map[string]bool{}
|
knownOIDs := make(map[string]bool, len(t.Fields))
|
||||||
for _, f := range t.Fields {
|
for _, f := range t.Fields {
|
||||||
knownOIDs[f.Oid] = true
|
knownOIDs[f.Oid] = true
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +118,7 @@ func (t *Table) initBuild() error {
|
||||||
|
|
||||||
// Build retrieves all the fields specified in the table and constructs the RTable.
|
// Build retrieves all the fields specified in the table and constructs the RTable.
|
||||||
func (t Table) Build(gs Connection, walk bool) (*RTable, error) {
|
func (t Table) Build(gs Connection, walk bool) (*RTable, error) {
|
||||||
rows := map[string]RTableRow{}
|
rows := make(map[string]RTableRow)
|
||||||
|
|
||||||
// translation table for secondary index (when performing join on two tables)
|
// translation table for secondary index (when performing join on two tables)
|
||||||
secIdxTab := make(map[string]string)
|
secIdxTab := make(map[string]string)
|
||||||
|
|
@ -151,7 +151,7 @@ func (t Table) Build(gs Connection, walk bool) (*RTable, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ifv contains a mapping of table OID index to field value
|
// ifv contains a mapping of table OID index to field value
|
||||||
ifv := map[string]interface{}{}
|
ifv := make(map[string]interface{})
|
||||||
|
|
||||||
if !walk {
|
if !walk {
|
||||||
// This is used when fetching non-table fields. Fields configured a the top
|
// This is used when fetching non-table fields. Fields configured a the top
|
||||||
|
|
@ -240,8 +240,8 @@ func (t Table) Build(gs Connection, walk bool) (*RTable, error) {
|
||||||
rtr, ok := rows[idx]
|
rtr, ok := rows[idx]
|
||||||
if !ok {
|
if !ok {
|
||||||
rtr = RTableRow{}
|
rtr = RTableRow{}
|
||||||
rtr.Tags = map[string]string{}
|
rtr.Tags = make(map[string]string)
|
||||||
rtr.Fields = map[string]interface{}{}
|
rtr.Fields = make(map[string]interface{})
|
||||||
rows[idx] = rtr
|
rows[idx] = rtr
|
||||||
}
|
}
|
||||||
if t.IndexAsTag && idx != "" {
|
if t.IndexAsTag && idx != "" {
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,10 @@ func (g *gosmiTranslator) SnmpFormatDisplayHint(oid string, value interface{}) (
|
||||||
|
|
||||||
func getIndex(mibPrefix string, node gosmi.SmiNode) (col []string, tagOids map[string]struct{}) {
|
func getIndex(mibPrefix string, node gosmi.SmiNode) (col []string, tagOids map[string]struct{}) {
|
||||||
// first attempt to get the table's tags
|
// first attempt to get the table's tags
|
||||||
tagOids = map[string]struct{}{}
|
|
||||||
|
|
||||||
// mimcks grabbing INDEX {} that is returned from snmptranslate -Td MibName
|
// mimcks grabbing INDEX {} that is returned from snmptranslate -Td MibName
|
||||||
for _, index := range node.GetIndex() {
|
indices := node.GetIndex()
|
||||||
|
tagOids = make(map[string]struct{}, len(indices))
|
||||||
|
for _, index := range indices {
|
||||||
tagOids[mibPrefix+index.Name] = struct{}{}
|
tagOids[mibPrefix+index.Name] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ func newMatcher(defaultTemplate *Template) *matcher {
|
||||||
|
|
||||||
func (m *matcher) addSpec(tmplt templateSpec) error {
|
func (m *matcher) addSpec(tmplt templateSpec) error {
|
||||||
// Parse out the default tags specific to this template
|
// Parse out the default tags specific to this template
|
||||||
tags := map[string]string{}
|
tags := make(map[string]string)
|
||||||
if tmplt.tagstring != "" {
|
if tmplt.tagstring != "" {
|
||||||
for _, kv := range strings.Split(tmplt.tagstring, ",") {
|
for _, kv := range strings.Split(tmplt.tagstring, ",") {
|
||||||
parts := strings.Split(kv, "=")
|
parts := strings.Split(kv, "=")
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
AgentMetricsWritten = selfstat.Register("agent", "metrics_written", map[string]string{})
|
AgentMetricsWritten = selfstat.Register("agent", "metrics_written", make(map[string]string))
|
||||||
AgentMetricsDropped = selfstat.Register("agent", "metrics_dropped", map[string]string{})
|
AgentMetricsDropped = selfstat.Register("agent", "metrics_dropped", make(map[string]string))
|
||||||
|
|
||||||
registerGob = sync.OnceFunc(func() { metric.Init() })
|
registerGob = sync.OnceFunc(func() { metric.Init() })
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GlobalMetricsGathered = selfstat.Register("agent", "metrics_gathered", map[string]string{})
|
GlobalMetricsGathered = selfstat.Register("agent", "metrics_gathered", make(map[string]string))
|
||||||
GlobalGatherErrors = selfstat.Register("agent", "gather_errors", map[string]string{})
|
GlobalGatherErrors = selfstat.Register("agent", "gather_errors", make(map[string]string))
|
||||||
GlobalGatherTimeouts = selfstat.Register("agent", "gather_timeouts", map[string]string{})
|
GlobalGatherTimeouts = selfstat.Register("agent", "gather_timeouts", make(map[string]string))
|
||||||
)
|
)
|
||||||
|
|
||||||
type RunningInput struct {
|
type RunningInput struct {
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ func walkXML(nodes []xmlnode, parents []string, separator string, f func(xmlnode
|
||||||
// UniqueFieldNames forms unique field names
|
// UniqueFieldNames forms unique field names
|
||||||
// by adding _<num> if there are several of them
|
// by adding _<num> if there are several of them
|
||||||
func UniqueFieldNames(fields []EventField, fieldsUsage map[string]int, separator string) []EventField {
|
func UniqueFieldNames(fields []EventField, fieldsUsage map[string]int, separator string) []EventField {
|
||||||
var fieldsCounter = map[string]int{}
|
var fieldsCounter = make(map[string]int, len(fields))
|
||||||
fieldsUnique := make([]EventField, 0, len(fields))
|
fieldsUnique := make([]EventField, 0, len(fields))
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
fieldName := field.Name
|
fieldName := field.Name
|
||||||
|
|
|
||||||
|
|
@ -156,10 +156,10 @@ func (w *WinEventLog) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
for i := range events {
|
for i := range events {
|
||||||
// Prepare fields names usage counter
|
// Prepare fields names usage counter
|
||||||
var fieldsUsage = map[string]int{}
|
fieldsUsage := make(map[string]int)
|
||||||
|
|
||||||
tags := map[string]string{}
|
tags := make(map[string]string)
|
||||||
fields := map[string]interface{}{}
|
fields := make(map[string]interface{})
|
||||||
event := events[i]
|
event := events[i]
|
||||||
evt := reflect.ValueOf(&event).Elem()
|
evt := reflect.ValueOf(&event).Elem()
|
||||||
timeStamp := time.Now()
|
timeStamp := time.Now()
|
||||||
|
|
@ -168,7 +168,7 @@ func (w *WinEventLog) Gather(acc telegraf.Accumulator) error {
|
||||||
fieldName := evt.Type().Field(i).Name
|
fieldName := evt.Type().Field(i).Name
|
||||||
fieldType := evt.Field(i).Type().String()
|
fieldType := evt.Field(i).Type().String()
|
||||||
fieldValue := evt.Field(i).Interface()
|
fieldValue := evt.Field(i).Interface()
|
||||||
computedValues := map[string]interface{}{}
|
computedValues := make(map[string]interface{})
|
||||||
switch fieldName {
|
switch fieldName {
|
||||||
case "Source":
|
case "Source":
|
||||||
fieldValue = event.Source.Name
|
fieldValue = event.Source.Name
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ func (m *Method) execute(acc telegraf.Accumulator) error {
|
||||||
defer outputPropertiesRaw.Clear()
|
defer outputPropertiesRaw.Clear()
|
||||||
|
|
||||||
// Convert the results to fields and tags
|
// Convert the results to fields and tags
|
||||||
tags, fields := map[string]string{}, map[string]interface{}{}
|
tags, fields := make(map[string]string), make(map[string]interface{})
|
||||||
|
|
||||||
// Add a source tag if we use remote queries
|
// Add a source tag if we use remote queries
|
||||||
if m.host != "" {
|
if m.host != "" {
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ func (q *Query) execute(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Query) extractProperties(acc telegraf.Accumulator, itemRaw *ole.VARIANT) error {
|
func (q *Query) extractProperties(acc telegraf.Accumulator, itemRaw *ole.VARIANT) error {
|
||||||
tags, fields := map[string]string{}, map[string]interface{}{}
|
tags, fields := make(map[string]string), make(map[string]interface{})
|
||||||
|
|
||||||
if q.host != "" {
|
if q.host != "" {
|
||||||
tags["source"] = q.host
|
tags["source"] = q.host
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ func Metrics() []telegraf.Metric {
|
||||||
if len(stats) > 0 {
|
if len(stats) > 0 {
|
||||||
var tags map[string]string
|
var tags map[string]string
|
||||||
var name string
|
var name string
|
||||||
fields := map[string]interface{}{}
|
fields := make(map[string]interface{}, len(stats))
|
||||||
j := 0
|
j := 0
|
||||||
for fieldname, stat := range stats {
|
for fieldname, stat := range stats {
|
||||||
if j == 0 {
|
if j == 0 {
|
||||||
|
|
|
||||||
|
|
@ -109,12 +109,12 @@ func (a *Accumulator) addMeasurement(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tagsCopy := map[string]string{}
|
tagsCopy := make(map[string]string, len(tags))
|
||||||
for k, v := range tags {
|
for k, v := range tags {
|
||||||
tagsCopy[k] = v
|
tagsCopy[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldsCopy := map[string]interface{}{}
|
fieldsCopy := make(map[string]interface{}, len(fields))
|
||||||
for k, v := range fields {
|
for k, v := range fields {
|
||||||
fieldsCopy[k] = v
|
fieldsCopy[k] = v
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func ImportConfigurations(files, dirs []string) (*selection, int, error) {
|
||||||
|
|
||||||
func (s *selection) Filter(p packageCollection) (*packageCollection, error) {
|
func (s *selection) Filter(p packageCollection) (*packageCollection, error) {
|
||||||
enabled := packageCollection{
|
enabled := packageCollection{
|
||||||
packages: map[string][]packageInfo{},
|
packages: make(map[string][]packageInfo),
|
||||||
}
|
}
|
||||||
|
|
||||||
implicitlyConfigured := make(map[string]bool)
|
implicitlyConfigured := make(map[string]bool)
|
||||||
|
|
|
||||||
|
|
@ -178,8 +178,8 @@ func main() {
|
||||||
|
|
||||||
// Get the superset of licenses
|
// Get the superset of licenses
|
||||||
if debug {
|
if debug {
|
||||||
licenseSet := map[string]bool{}
|
licenseSet := make(map[string]bool, len(packageInfos))
|
||||||
licenseNames := []string{}
|
licenseNames := make([]string, 0, len(packageInfos))
|
||||||
for _, info := range packageInfos {
|
for _, info := range packageInfos {
|
||||||
if found := licenseSet[info.license]; !found {
|
if found := licenseSet[info.license]; !found {
|
||||||
licenseNames = append(licenseNames, info.license)
|
licenseNames = append(licenseNames, info.license)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue