@@ -0,0 +1,37 @@
|
|||||||
|
package toml_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/pelletier/go-toml/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type customInt int
|
||||||
|
|
||||||
|
func (i *customInt) UnmarshalText(b []byte) error {
|
||||||
|
x, err := strconv.ParseInt(string(b), 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*i = customInt(x * 100)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type doc struct {
|
||||||
|
Value customInt
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleUnmarshal_textUnmarshal() {
|
||||||
|
var x doc
|
||||||
|
|
||||||
|
data := []byte(`value = "42"`)
|
||||||
|
err := toml.Unmarshal(data, &x)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Println(x)
|
||||||
|
// Output:
|
||||||
|
// {4200}
|
||||||
|
}
|
||||||
@@ -90,7 +90,6 @@ func ExampleUnmarshal() {
|
|||||||
fmt.Println("version:", cfg.Version)
|
fmt.Println("version:", cfg.Version)
|
||||||
fmt.Println("name:", cfg.Name)
|
fmt.Println("name:", cfg.Name)
|
||||||
fmt.Println("tags:", cfg.Tags)
|
fmt.Println("tags:", cfg.Tags)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// version: 2
|
// version: 2
|
||||||
// name: go-toml
|
// name: go-toml
|
||||||
|
|||||||
Reference in New Issue
Block a user