✨ Make IntOrString support TOML as well
This commit is contained in:
parent
f4497aef7e
commit
e8401db519
3 changed files with 77 additions and 17 deletions
25
types/toml.go
Normal file
25
types/toml.go
Normal 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}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue