Fantom-foundation/go-lachesis

View on GitHub
utils/toml/settings.go

Summary

Maintainability
A
0 mins
Test Coverage
package toml

import (
    "fmt"
    "reflect"
    "unicode"

    "github.com/naoina/toml"
)

// Settings ensure that TOML keys use the same names as Go struct fields.
var Settings = toml.Config{
    NormFieldName: func(rt reflect.Type, key string) string {
        return key
    },
    FieldToKey: func(rt reflect.Type, field string) string {
        return field
    },
    MissingField: func(rt reflect.Type, field string) error {
        link := ""
        if unicode.IsUpper(rune(rt.Name()[0])) && rt.PkgPath() != "main" {
            link = fmt.Sprintf(", see https://godoc.org/%s#%s for available fields", rt.PkgPath(), rt.Name())
        }
        return fmt.Errorf("field '%s' is not defined in %s%s", field, rt.String(), link)
    },
}