From 582d271f3b141298a592318499c9b1f8758596bd Mon Sep 17 00:00:00 2001 From: Philipp Mieden Date: Sat, 12 Jan 2019 21:46:58 +0100 Subject: [PATCH] replaced strings.Join usage with join func --- types/ciscoDiscovery.go | 2 +- types/ciscoDiscoveryInfo.go | 54 ++++++++++++++++++------------------- types/dns.go | 2 +- types/http.go | 6 +---- types/igmp.go | 4 +-- types/lld.go | 9 +++---- types/sip.go | 3 +-- 7 files changed, 37 insertions(+), 43 deletions(-) diff --git a/types/ciscoDiscovery.go b/types/ciscoDiscovery.go index 247b400e..86f249ef 100644 --- a/types/ciscoDiscovery.go +++ b/types/ciscoDiscovery.go @@ -38,7 +38,7 @@ func (a CiscoDiscovery) CSVRecord() []string { formatInt32(a.Version), // int32 formatInt32(a.TTL), // int32 formatInt32(a.Checksum), // int32 - strings.Join(vals, "|"), // []*CiscoDiscoveryValue + join(vals...), // []*CiscoDiscoveryValue }) } diff --git a/types/ciscoDiscoveryInfo.go b/types/ciscoDiscoveryInfo.go index 82494420..435158c9 100644 --- a/types/ciscoDiscoveryInfo.go +++ b/types/ciscoDiscoveryInfo.go @@ -64,32 +64,32 @@ func (a CiscoDiscoveryInfo) CSVRecord() []string { } return filter([]string{ formatTimestamp(a.Timestamp), - a.CDPHello.ToString(), // *CDPHello - a.DeviceID, // string - strings.Join(a.Addresses, "|"), // []string - a.PortID, // string - a.Capabilities.ToString(), // *CDPCapabilities - a.Version, // string - a.Platform, // string - strings.Join(ipNets, "|"), // []*IPNet - a.VTPDomain, // string - formatInt32(a.NativeVLAN), // int32 - strconv.FormatBool(a.FullDuplex), // bool - a.VLANReply.ToString(), // *CDPVLANDialogue - a.VLANQuery.ToString(), // *CDPVLANDialogue - formatInt32(a.PowerConsumption), // int32 - formatUint32(a.MTU), // uint32 - formatInt32(a.ExtendedTrust), // int32 - formatInt32(a.UntrustedCOS), // int32 - a.SysName, // string - a.SysOID, // string - strings.Join(a.MgmtAddresses, "|"), // []string - a.Location.ToString(), // *CDPLocation - a.PowerRequest.ToString(), // *CDPPowerDialogue - a.PowerAvailable.ToString(), // *CDPPowerDialogue - a.SparePairPoe.ToString(), // *CDPSparePairPoE - a.EnergyWise.ToString(), // *CDPEnergyWise - strings.Join(vals, "|"), // []*CiscoDiscoveryValue + a.CDPHello.ToString(), // *CDPHello + a.DeviceID, // string + join(a.Addresses...), // []string + a.PortID, // string + a.Capabilities.ToString(), // *CDPCapabilities + a.Version, // string + a.Platform, // string + join(ipNets...), // []*IPNet + a.VTPDomain, // string + formatInt32(a.NativeVLAN), // int32 + strconv.FormatBool(a.FullDuplex), // bool + a.VLANReply.ToString(), // *CDPVLANDialogue + a.VLANQuery.ToString(), // *CDPVLANDialogue + formatInt32(a.PowerConsumption), // int32 + formatUint32(a.MTU), // uint32 + formatInt32(a.ExtendedTrust), // int32 + formatInt32(a.UntrustedCOS), // int32 + a.SysName, // string + a.SysOID, // string + join(a.MgmtAddresses...), // []string + a.Location.ToString(), // *CDPLocation + a.PowerRequest.ToString(), // *CDPPowerDialogue + a.PowerAvailable.ToString(), // *CDPPowerDialogue + a.SparePairPoe.ToString(), // *CDPSparePairPoE + a.EnergyWise.ToString(), // *CDPEnergyWise + join(vals...), // []*CiscoDiscoveryValue }) } @@ -197,7 +197,7 @@ func (c CDPPowerDialogue) ToString() string { b.WriteString(sep) b.WriteString(formatInt32(c.MgmtID)) b.WriteString(sep) - b.WriteString(strings.Join(vals, "|")) + b.WriteString(join(vals...)) b.WriteString(end) return b.String() diff --git a/types/dns.go b/types/dns.go index 03e1f147..36132eac 100644 --- a/types/dns.go +++ b/types/dns.go @@ -129,7 +129,7 @@ func (q DNSResourceRecord) ToString() string { b.WriteString(sep) b.WriteString(q.MX.ToString()) b.WriteString(sep) - b.WriteString(strings.Join(txts, "/")) + b.WriteString(join(txts...)) b.WriteString(end) return b.String() } diff --git a/types/http.go b/types/http.go index 4f105f81..09afd309 100644 --- a/types/http.go +++ b/types/http.go @@ -13,10 +13,6 @@ package types -import ( - "strings" -) - func (h HTTP) CSVHeader() []string { return filter([]string{ "Timestamp", @@ -44,7 +40,7 @@ func (h HTTP) CSVRecord() []string { h.Host, h.UserAgent, h.Referer, - strings.Join(h.ReqCookies, "/"), + join(h.ReqCookies), formatInt32(h.ReqContentLength), h.URL, formatInt32(h.ResContentLength), diff --git a/types/igmp.go b/types/igmp.go index 3cc8dbef..b7d4ec3e 100644 --- a/types/igmp.go +++ b/types/igmp.go @@ -51,7 +51,7 @@ func (i IGMP) CSVRecord() []string { strconv.FormatBool(i.SupressRouterProcessing), // bool formatInt32(i.RobustnessValue), // int32 formatUint64(i.IntervalTime), // uint64 - strings.Join(i.SourceAddresses, "/"), // []string + join(i.SourceAddresses...), // []string formatInt32(i.NumberOfGroupRecords), // int32 formatInt32(i.NumberOfSources), // int32 strings.Join(records, ""), // []*IGMPv3GroupRecord @@ -75,7 +75,7 @@ func (i IGMPv3GroupRecord) ToString() string { b.WriteString(sep) b.WriteString(i.MulticastAddress) b.WriteString(sep) - b.WriteString(strings.Join(i.SourceAddresses, "/")) + b.WriteString(join(i.SourceAddresses...)) b.WriteString(end) return b.String() diff --git a/types/lld.go b/types/lld.go index ae1a307e..6492ccdf 100644 --- a/types/lld.go +++ b/types/lld.go @@ -15,7 +15,6 @@ package types import ( "encoding/hex" - "strings" ) func (l LinkLayerDiscovery) CSVHeader() []string { @@ -35,10 +34,10 @@ func (l LinkLayerDiscovery) CSVRecord() []string { } return filter([]string{ formatTimestamp(l.Timestamp), - l.ChassisID.ToString(), // *LLDPChassisID - l.PortID.ToString(), // *LLDPPortID - formatInt32(l.TTL), // int32 - strings.Join(values, "/"), // []*LinkLayerDiscoveryValue + l.ChassisID.ToString(), // *LLDPChassisID + l.PortID.ToString(), // *LLDPPortID + formatInt32(l.TTL), // int32 + join(values...), // []*LinkLayerDiscoveryValue }) } diff --git a/types/sip.go b/types/sip.go index ded63052..29276b1b 100644 --- a/types/sip.go +++ b/types/sip.go @@ -15,7 +15,6 @@ package types import ( "strconv" - "strings" ) func (s SIP) CSVHeader() []string { @@ -32,7 +31,7 @@ func (s SIP) CSVRecord() []string { s.Timestamp, // string `protobuf:"bytes,1,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` formatInt32(s.Version), // int32 `protobuf:"varint,2,opt,name=Version,proto3" json:"Version,omitempty"` formatInt32(s.Method), // int32 `protobuf:"varint,3,opt,name=Method,proto3" json:"Method,omitempty"` - strings.Join(s.Headers, "/"), // []string `protobuf:"bytes,4,rep,name=Headers,proto3" json:"Headers,omitempty"` + join(s.Headers...), // []string `protobuf:"bytes,4,rep,name=Headers,proto3" json:"Headers,omitempty"` strconv.FormatBool(s.IsResponse), // bool `protobuf:"varint,5,opt,name=IsResponse,proto3" json:"IsResponse,omitempty"` formatInt32(s.ResponseCode), // int32 `protobuf:"varint,6,opt,name=ResponseCode,proto3" json:"ResponseCode,omitempty"` s.ResponseStatus, // string `protobuf