move: advanced funcs to functional programming

This commit is contained in:
Inanc Gumus
2019-08-06 01:34:36 +03:00
parent c97becdf82
commit 4e8b80c519
27 changed files with 417 additions and 181 deletions

View File

@@ -0,0 +1,20 @@
package main
import (
"fmt"
"strconv"
)
// field helps for field parsing
type field struct{ err error }
// uatoi parses an unsigned integer string and saves the error.
// it assumes that the val is unsigned.
// for ease of usability: it returns an int instead of uint.
func (f *field) uatoi(name, val string) int {
n, err := strconv.Atoi(val)
if n < 0 || err != nil {
f.err = fmt.Errorf("incorrect field -> %q = %q", name, val)
}
return n
}