Make IntOrString support TOML as well

This commit is contained in:
Dan Jones 2025-07-18 16:55:54 -05:00
commit e8401db519
3 changed files with 77 additions and 17 deletions

25
types/toml.go Normal file
View file

@ -0,0 +1,25 @@
package types
import "fmt"
type TomlTypeError struct {
Value any
}
func (te *TomlTypeError) Error() string {
return fmt.Sprintf("unsupported type: %T", te.Value)
}
func (is *IntOrString) UnmarshalTOML(val any) error {
switch v := val.(type) {
case string:
is.isInt = false
is.strVal = v
return nil
case int64:
is.isInt = true
is.intVal = int(v)
return nil
}
return &TomlTypeError{Value: val}
}