Assisted-by: GLM 5.3 Flash
This commit is contained in:
+15
-2
@@ -241,7 +241,9 @@ func UnmarshalContext(ctx context.Context, data []byte, v any) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return newDecoder().decode(tree, v)
|
||||
dec := newDecoder()
|
||||
dec.ctx = ctx
|
||||
return dec.decode(tree, v)
|
||||
}
|
||||
|
||||
// A Decoder decodes a TOML document into a Go value with configurable
|
||||
@@ -315,6 +317,7 @@ func (d *Decoder) DecodeContext(ctx context.Context, data []byte, v any) error {
|
||||
}
|
||||
dec := newDecoder()
|
||||
dec.disallowUnknown = d.disallowUnknown
|
||||
dec.ctx = ctx
|
||||
return dec.decode(tree, v)
|
||||
}
|
||||
|
||||
@@ -336,7 +339,8 @@ type Marshaler interface {
|
||||
// argument is whatever the parser produced for that key: one of string,
|
||||
// bool, int64, float64, OffsetDateTime, LocalDateTime, LocalDate, LocalTime,
|
||||
// []any, or map[string]any. A tree built by hand may carry a plain time.Time
|
||||
// where the parser would put an OffsetDateTime.
|
||||
// where the parser would put an OffsetDateTime, and a Decoder configured with
|
||||
// UseNumber a Number.
|
||||
//
|
||||
// UnmarshalTOML may parse, inspect, or transform the value however it likes,
|
||||
// then store the result by mutating its receiver through the standard
|
||||
@@ -355,6 +359,15 @@ type Unmarshaler interface {
|
||||
UnmarshalTOML(data any) error
|
||||
}
|
||||
|
||||
// UnmarshalerContext is Unmarshaler with the decode's context handed in. A
|
||||
// type that implements both interfaces gets UnmarshalTOMLContext, so a long
|
||||
// custom decode can abort on cancellation instead of running to completion.
|
||||
// The context a non-cancellable entry point carries is context.Background,
|
||||
// never nil.
|
||||
type UnmarshalerContext interface {
|
||||
UnmarshalTOMLContext(ctx context.Context, data any) error
|
||||
}
|
||||
|
||||
// Marshal returns the TOML encoding of v. The output is valid TOML 1.1.
|
||||
//
|
||||
// Marshal traverses v using reflection and applies the following rules:
|
||||
|
||||
Reference in New Issue
Block a user