Spot the bug in port selection

from Go fundamentals
Go 1.27 intermediate 4 min 1 issue to find

Find why a valid custom port is parsed but the function still returns 8080.

Go
func selectPort(raw string) (int, error) {
    port := 8080
    if raw != "" {
        port, err := strconv.Atoi(raw)
        if err != nil {
            return 0, err
        }
        if port < 1 || port > 65535 {
            return 0, fmt.Errorf("port out of range")
        }
    }
    return port, nil
}
Open in playground
Report an error