Added unit tests, documentation and function descriptions across the board. Increased cyclop complexity threshold to 15 which is a bit more sane than 10 and excluded _test.go files from linters.
This commit is contained in:
1 parent
005b335371
commit
7fd321df97
31 files changed
+4106
-1
No files matched your search
@@ -205,6 +205,9 @@ func setValue(ptr any, key string, value any) error {
|
||||
return setField(section, f, value)
|
||||
}
|
||||
|
||||
// setField converts value to the field's type and, if the section has a
|
||||
// validator, checks it, before setting the field. On error the field is left
|
||||
// unchanged.
|
||||
func setField(section reflect.Value, f field, value any) error {
|
||||
newValue, err := convert(value, f.typ)
|
||||
if err != nil {
|
||||
@@ -234,6 +237,8 @@ func convert(value any, t reflect.Type) (reflect.Value, error) {
|
||||
return reflect.Value{}, fmt.Errorf("unsupported type %T", value)
|
||||
}
|
||||
|
||||
// parseString parses s as a value of type t. It supports strings, bools,
|
||||
// signed and unsigned integers, floats and time.Duration.
|
||||
func parseString(s string, t reflect.Type) (reflect.Value, error) {
|
||||
v := reflect.New(t).Elem()
|
||||
if t == durationType {
|
||||
@@ -280,6 +285,9 @@ func applyDefaults(ptr any) error {
|
||||
return applyDefaultsTo("", structValue(ptr))
|
||||
}
|
||||
|
||||
// applyDefaultsTo sets every field in section that has a default tag,
|
||||
// recursing into nested sections. prefix is the section's dotted key, used in
|
||||
// error messages.
|
||||
func applyDefaultsTo(prefix string, section reflect.Value) error {
|
||||
for _, f := range fieldsOf(section.Type()) {
|
||||
key := joinKey(prefix, f.key)
|
||||
|
||||
Reference in new issue
Block a user