Skip to content

Commit 17ef72d

Browse files
committed
Tweak docs to use Go 1.19 syntax
1 parent 1ba7f5b commit 17ef72d

File tree

7 files changed

+58
-57
lines changed

7 files changed

+58
-57
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: arp242

decode.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@ type Unmarshaler interface {
2121
UnmarshalTOML(interface{}) error
2222
}
2323

24-
// Unmarshal decodes the contents of `data` in TOML format into a pointer `v`.
24+
// Unmarshal decodes the contents of data in TOML format into a pointer v.
25+
//
26+
// See [Decoder] for a description of the decoding process.
2527
func Unmarshal(data []byte, v interface{}) error {
2628
_, err := NewDecoder(bytes.NewReader(data)).Decode(v)
2729
return err
2830
}
2931

3032
// Decode the TOML data in to the pointer v.
3133
//
32-
// See the documentation on Decoder for a description of the decoding process.
34+
// See [Decoder] for a description of the decoding process.
3335
func Decode(data string, v interface{}) (MetaData, error) {
3436
return NewDecoder(strings.NewReader(data)).Decode(v)
3537
}
3638

37-
// DecodeFile is just like Decode, except it will automatically read the
38-
// contents of the file at path and decode it for you.
39+
// DecodeFile reads the contents of a file and decodes it with [Decode].
3940
func DecodeFile(path string, v interface{}) (MetaData, error) {
4041
fp, err := os.Open(path)
4142
if err != nil {
@@ -48,7 +49,7 @@ func DecodeFile(path string, v interface{}) (MetaData, error) {
4849
// Primitive is a TOML value that hasn't been decoded into a Go value.
4950
//
5051
// This type can be used for any value, which will cause decoding to be delayed.
51-
// You can use the PrimitiveDecode() function to "manually" decode these values.
52+
// You can use [PrimitiveDecode] to "manually" decode these values.
5253
//
5354
// NOTE: The underlying representation of a `Primitive` value is subject to
5455
// change. Do not rely on it.
@@ -70,15 +71,15 @@ const (
7071

7172
// Decoder decodes TOML data.
7273
//
73-
// TOML tables correspond to Go structs or maps (dealer's choice – they can be
74-
// used interchangeably).
74+
// TOML tables correspond to Go structs or maps; they can be used
75+
// interchangeably, but structs offer better type safety.
7576
//
7677
// TOML table arrays correspond to either a slice of structs or a slice of maps.
7778
//
78-
// TOML datetimes correspond to Go time.Time values. Local datetimes are parsed
79-
// in the local timezone.
79+
// TOML datetimes correspond to [time.Time]. Local datetimes are parsed in the
80+
// local timezone.
8081
//
81-
// time.Duration types are treated as nanoseconds if the TOML value is an
82+
// [time.Duration] types are treated as nanoseconds if the TOML value is an
8283
// integer, or they're parsed with time.ParseDuration() if they're strings.
8384
//
8485
// All other TOML types (float, string, int, bool and array) correspond to the
@@ -90,7 +91,7 @@ const (
9091
// UnmarshalText method. See the Unmarshaler example for a demonstration with
9192
// email addresses.
9293
//
93-
// Key mapping
94+
// ### Key mapping
9495
//
9596
// TOML keys can map to either keys in a Go map or field names in a Go struct.
9697
// The special `toml` struct tag can be used to map TOML keys to struct fields
@@ -168,17 +169,16 @@ func (dec *Decoder) Decode(v interface{}) (MetaData, error) {
168169
return md, md.unify(p.mapping, rv)
169170
}
170171

171-
// PrimitiveDecode is just like the other `Decode*` functions, except it
172-
// decodes a TOML value that has already been parsed. Valid primitive values
173-
// can *only* be obtained from values filled by the decoder functions,
174-
// including this method. (i.e., `v` may contain more `Primitive`
175-
// values.)
172+
// PrimitiveDecode is just like the other Decode* functions, except it decodes a
173+
// TOML value that has already been parsed. Valid primitive values can *only* be
174+
// obtained from values filled by the decoder functions, including this method.
175+
// (i.e., v may contain more [Primitive] values.)
176176
//
177-
// Meta data for primitive values is included in the meta data returned by
178-
// the `Decode*` functions with one exception: keys returned by the Undecoded
179-
// method will only reflect keys that were decoded. Namely, any keys hidden
180-
// behind a Primitive will be considered undecoded. Executing this method will
181-
// update the undecoded keys in the meta data. (See the example.)
177+
// Meta data for primitive values is included in the meta data returned by the
178+
// Decode* functions with one exception: keys returned by the Undecoded method
179+
// will only reflect keys that were decoded. Namely, any keys hidden behind a
180+
// Primitive will be considered undecoded. Executing this method will update the
181+
// undecoded keys in the meta data. (See the example.)
182182
func (md *MetaData) PrimitiveDecode(primValue Primitive, v interface{}) error {
183183
md.context = primValue.context
184184
defer func() { md.context = nil }()

decode_go116.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"io/fs"
88
)
99

10-
// DecodeFS is just like Decode, except it will automatically read the contents
11-
// of the file at `path` from a fs.FS instance.
10+
// DecodeFS reads the contents of a file from [fs.FS] and decodes it with
11+
// [Decode].
1212
func DecodeFS(fsys fs.FS, path string, v interface{}) (MetaData, error) {
1313
fp, err := fsys.Open(path)
1414
if err != nil {

doc.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
/*
2-
Package toml implements decoding and encoding of TOML files.
3-
4-
This package supports TOML v1.0.0, as listed on https://toml.io
5-
6-
There is also support for delaying decoding with the Primitive type, and
7-
querying the set of keys in a TOML document with the MetaData type.
8-
9-
The github.com/BurntSushi/toml/cmd/tomlv package implements a TOML validator,
10-
and can be used to verify if TOML document is valid. It can also be used to
11-
print the type of each key.
12-
*/
1+
// Package toml implements decoding and encoding of TOML files.
2+
//
3+
// This package supports TOML v1.0.0, as specified at https://toml.io
4+
//
5+
// There is also support for delaying decoding with the Primitive type, and
6+
// querying the set of keys in a TOML document with the MetaData type.
7+
//
8+
// The github.com/BurntSushi/toml/cmd/tomlv package implements a TOML validator,
9+
// and can be used to verify if TOML document is valid. It can also be used to
10+
// print the type of each key.
1311
package toml

encode.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ type Marshaler interface {
7979
// Encoder encodes a Go to a TOML document.
8080
//
8181
// The mapping between Go values and TOML values should be precisely the same as
82-
// for the Decode* functions.
82+
// for [Decode].
8383
//
8484
// time.Time is encoded as a RFC 3339 string, and time.Duration as its string
8585
// representation.
8686
//
87-
// The toml.Marshaler and encoder.TextMarshaler interfaces are supported to
87+
// The [Marshaler] and [encoding.TextMarshaler] interfaces are supported to
8888
// encoding the value as custom TOML.
8989
//
9090
// If you want to write arbitrary binary data then you will need to use
@@ -99,9 +99,9 @@ type Marshaler interface {
9999
// struct field name will be used. If the "omitempty" option is present the
100100
// following value will be skipped:
101101
//
102-
// - arrays, slices, maps, and string with len of 0
103-
// - struct with all zero values
104-
// - bool false
102+
// - arrays, slices, maps, and string with len of 0
103+
// - struct with all zero values
104+
// - bool false
105105
//
106106
// If omitzero is given all int and float types with a value of 0 will be
107107
// skipped.
@@ -130,7 +130,7 @@ func NewEncoder(w io.Writer) *Encoder {
130130
}
131131
}
132132

133-
// Encode writes a TOML representation of the Go value to the Encoder's writer.
133+
// Encode writes a TOML representation of the Go value to the [Encoder]'s writer.
134134
//
135135
// An error is returned if the value given cannot be encoded to a valid TOML
136136
// document.
@@ -676,11 +676,10 @@ func (enc *Encoder) newline() {
676676
// This is also used for "k = v" in inline tables; so something like this will
677677
// be written in three calls:
678678
//
679-
// ┌────────────────────┐
680-
// │ ┌───┐ ┌─────┐│
681-
// v v v v vv
682-
// key = {k = v, k2 = v2}
683-
//
679+
// ┌───────────────────┐
680+
// │ ┌───┐ ┌────┐│
681+
// v v v v vv
682+
// key = {k = 1, k2 = 2}
684683
func (enc *Encoder) writeKeyValue(key Key, val reflect.Value, inline bool) {
685684
if len(key) == 0 {
686685
encPanic(errNoKey)

error.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import (
55
"strings"
66
)
77

8-
// ParseError is returned when there is an error parsing the TOML syntax.
9-
//
10-
// For example invalid syntax, duplicate keys, etc.
8+
// ParseError is returned when there is an error parsing the TOML syntax such as
9+
// invalid syntax, duplicate keys, etc.
1110
//
1211
// In addition to the error message itself, you can also print detailed location
13-
// information with context by using ErrorWithPosition():
12+
// information with context by using [ErrorWithPosition]:
1413
//
1514
// toml: error: Key 'fruit' was already created and cannot be used as an array.
1615
//
@@ -21,8 +20,8 @@ import (
2120
// 4 | [[fruit]] # Not allowed
2221
// ^^^^^
2322
//
24-
// Furthermore, the ErrorWithUsage() can be used to print the above with some
25-
// more detailed usage guidance:
23+
// [ErrorWithUsage] can be used to print the above with some more detailed usage
24+
// guidance:
2625
//
2726
// toml: error: newlines not allowed within inline tables
2827
//
@@ -55,7 +54,11 @@ type ParseError struct {
5554
Usage string // Longer message with usage guidance; may be blank.
5655
Position Position // Position of the error
5756
LastKey string // Last parsed key, may be blank.
58-
Line int // Line the error occurred. Deprecated: use Position.
57+
58+
// Line the error occurred.
59+
//
60+
// Deprecated: use [Position].
61+
Line int
5962

6063
err error
6164
input string
@@ -83,7 +86,7 @@ func (pe ParseError) Error() string {
8386

8487
// ErrorWithUsage() returns the error with detailed location context.
8588
//
86-
// See the documentation on ParseError.
89+
// See the documentation on [ParseError].
8790
func (pe ParseError) ErrorWithPosition() string {
8891
if pe.input == "" { // Should never happen, but just in case.
8992
return pe.Error()
@@ -124,7 +127,7 @@ func (pe ParseError) ErrorWithPosition() string {
124127
// ErrorWithUsage() returns the error with detailed location context and usage
125128
// guidance.
126129
//
127-
// See the documentation on ParseError.
130+
// See the documentation on [ParseError].
128131
func (pe ParseError) ErrorWithUsage() string {
129132
m := pe.ErrorWithPosition()
130133
if u, ok := pe.err.(interface{ Usage() string }); ok && u.Usage() != "" {

meta.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (md *MetaData) Keys() []Key {
7171
// Undecoded returns all keys that have not been decoded in the order in which
7272
// they appear in the original TOML document.
7373
//
74-
// This includes keys that haven't been decoded because of a Primitive value.
74+
// This includes keys that haven't been decoded because of a [Primitive] value.
7575
// Once the Primitive value is decoded, the keys will be considered decoded.
7676
//
7777
// Also note that decoding into an empty interface will result in no decoding,
@@ -89,7 +89,7 @@ func (md *MetaData) Undecoded() []Key {
8989
return undecoded
9090
}
9191

92-
// Key represents any TOML key, including key groups. Use (MetaData).Keys to get
92+
// Key represents any TOML key, including key groups. Use [MetaData.Keys] to get
9393
// values of this type.
9494
type Key []string
9595

0 commit comments

Comments
 (0)