You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
674 B
41 lines
674 B
package toml
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"gitoa.ru/go-4devs/config"
|
|
"gitoa.ru/go-4devs/config/value"
|
|
)
|
|
|
|
type Value struct {
|
|
value.Value
|
|
}
|
|
|
|
func (s Value) Int() int {
|
|
v, _ := s.ParseInt()
|
|
|
|
return v
|
|
}
|
|
|
|
func (s Value) ParseInt() (int, error) {
|
|
v, err := s.ParseInt64()
|
|
if err != nil {
|
|
return 0, fmt.Errorf("toml failed parce int: %w", err)
|
|
}
|
|
|
|
return int(v), nil
|
|
}
|
|
|
|
func (s Value) Unmarshal(target interface{}) error {
|
|
b, err := json.Marshal(s.Raw())
|
|
if err != nil {
|
|
return fmt.Errorf("%w: %s", config.ErrInvalidValue, err)
|
|
}
|
|
|
|
if err := json.Unmarshal(b, target); err != nil {
|
|
return fmt.Errorf("%w: %s", config.ErrInvalidValue, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|