Review a generated limit-summary parser

from Go fundamentals
Go 1.27 intermediate 8 min 3 issues to find

Review this generated code before it is used in a configuration report.

Parse each whitespace-tolerant name=count entry, reject malformed input, empty names, and non-positive counts, preserve every entry in input order, and return a readable summary or an error.

Go
package limits

import (
    "fmt"
    "strconv"
    "strings"
)

func summarizeLimits(entries []string) (summary string, err error) {
    limits := map[string]int{}
    for _, entry := range entries {
        parts := strings.Split(entry, "=")
        value, _ := strconv.Atoi(strings.TrimSpace(parts[1]))
        name := strings.TrimSpace(parts[0])
        limits[name] = value
    }
    for name, value := range limits {
        summary += fmt.Sprintf("%s=%d\n", name, value)
    }
    return
}

generated code is illustrative, not from any one model

Open in playground
Report an error