[#47] netmap: Make PlacementPolicy.WriteStringTo() pass nofunlen, cogognit

REP statement is obligatory, thus insert newline before each statement
after REP.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-04-07 08:38:08 +03:00
parent 25e9336d68
commit 31271ad8b1

View file

@ -393,49 +393,28 @@ func (p *PlacementPolicy) AddFilters(fs ...Filter) {
// the result into w. Returns w's errors directly. // the result into w. Returns w's errors directly.
// //
// See also DecodeString. // See also DecodeString.
//
// nolint: funlen, gocognit
func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) { func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) {
writtenSmth := false delim := ""
writeLnIfNeeded := func() error {
if writtenSmth {
_, err = w.WriteString("\n")
return err
}
writtenSmth = true
return nil
}
for i := range p.replicas { for i := range p.replicas {
err = writeLnIfNeeded()
if err != nil {
return err
}
c := p.replicas[i].GetCount() c := p.replicas[i].GetCount()
s := p.replicas[i].GetSelector() s := p.replicas[i].GetSelector()
if s != "" { if s != "" {
_, err = w.WriteString(fmt.Sprintf("REP %d IN %s", c, s)) _, err = w.WriteString(fmt.Sprintf("%sREP %d IN %s", delim, c, s))
} else { } else {
_, err = w.WriteString(fmt.Sprintf("REP %d", c)) _, err = w.WriteString(fmt.Sprintf("%sREP %d", delim, c))
} }
if err != nil { if err != nil {
return err return err
} }
delim = "\n"
} }
if p.backupFactor > 0 { if p.backupFactor > 0 {
err = writeLnIfNeeded() _, err = w.WriteString(fmt.Sprintf("\nCBF %d", p.backupFactor))
if err != nil {
return err
}
_, err = w.WriteString(fmt.Sprintf("CBF %d", p.backupFactor))
if err != nil { if err != nil {
return err return err
} }
@ -444,12 +423,7 @@ func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) {
var s string var s string
for i := range p.selectors { for i := range p.selectors {
err = writeLnIfNeeded() _, err = w.WriteString(fmt.Sprintf("\nSELECT %d", p.selectors[i].GetCount()))
if err != nil {
return err
}
_, err = w.WriteString(fmt.Sprintf("SELECT %d", p.selectors[i].GetCount()))
if err != nil { if err != nil {
return err return err
} }
@ -488,12 +462,7 @@ func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) {
} }
for i := range p.filters { for i := range p.filters {
err = writeLnIfNeeded() _, err = w.WriteString("\nFILTER ")
if err != nil {
return err
}
_, err = w.WriteString("FILTER ")
if err != nil { if err != nil {
return err return err
} }