Skip to content

Commit 313f8c4

Browse files
committed
feat(configio): make Representation private
- configio.Representation -> configio.representation - make all representation methods private
1 parent 0637323 commit 313f8c4

6 files changed

Lines changed: 24 additions & 24 deletions

File tree

configio/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (b *Builder) WriteYAML(in []byte) error {
3333
}
3434

3535
func (b *Builder) decodeAndWrite(in []byte, format Format) error {
36-
repr := Representation{}
36+
repr := representation{}
3737
if err := DecoderOf(format, in).Decode(&repr); err != nil {
3838
return err
3939
}
@@ -43,7 +43,7 @@ func (b *Builder) decodeAndWrite(in []byte, format Format) error {
4343
}
4444
b.append(func(dst *benchttp.Runner) {
4545
// err is already checked via repr.validate(), so nil is expected.
46-
if err := repr.Into(dst); err != nil {
46+
if err := repr.parseAndMutate(dst); err != nil {
4747
panicInternal("Builder.decodeAndWrite", "unexpected error: "+err.Error())
4848
}
4949
})

configio/decoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
type Decoder interface {
11-
Decode(dst *Representation) error
11+
Decode(dst *representation) error
1212
DecodeRunner(dst *benchttp.Runner) error
1313
}
1414

configio/file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func UnmarshalFile(filename string, dst *benchttp.Runner) error {
4949
type file struct {
5050
prev *file
5151
path string
52-
repr Representation
52+
repr representation
5353
}
5454

5555
// decodeAll reads f.path as a file and decodes it into f.repr.
@@ -122,7 +122,7 @@ func (f file) seen(p string) bool {
122122
// reprs returns a slice of Representation, starting with the receiver
123123
// and ending with the last child.
124124
func (f file) reprs() representations {
125-
reprs := []Representation{f.repr}
125+
reprs := []representation{f.repr}
126126
if f.prev != nil {
127127
reprs = append(reprs, f.prev.reprs()...)
128128
}

configio/json.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// UnmarshalJSON parses the JSON-encoded data and stores the result
1515
// in the Representation pointed to by dst.
16-
func UnmarshalJSON(in []byte, dst *Representation) error {
16+
func UnmarshalJSON(in []byte, dst *representation) error {
1717
dec := NewJSONDecoder(bytes.NewReader(in))
1818
return dec.Decode(dst)
1919
}
@@ -34,7 +34,7 @@ func NewJSONDecoder(r io.Reader) JSONDecoder {
3434

3535
// Decode reads the next JSON-encoded value from its input
3636
// and stores it in the Representation pointed to by dst.
37-
func (d JSONDecoder) Decode(dst *Representation) error {
37+
func (d JSONDecoder) Decode(dst *representation) error {
3838
decoder := json.NewDecoder(d.r)
3939
decoder.DisallowUnknownFields()
4040
return d.handleError(decoder.Decode(dst))
@@ -43,11 +43,11 @@ func (d JSONDecoder) Decode(dst *Representation) error {
4343
// Decode reads the next JSON-encoded value from its input
4444
// and stores it in the benchttp.Runner pointed to by dst.
4545
func (d JSONDecoder) DecodeRunner(dst *benchttp.Runner) error {
46-
repr := Representation{}
46+
repr := representation{}
4747
if err := d.Decode(&repr); err != nil {
4848
return err
4949
}
50-
return repr.Into(dst)
50+
return repr.parseAndMutate(dst)
5151
}
5252

5353
// handleError handles an error from package json,

configio/representation.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"github.com/benchttp/sdk/internal/errorutil"
1515
)
1616

17-
// Representation is a raw data model for formatted runner config (json, yaml).
17+
// representation is a raw data model for formatted runner config (json, yaml).
1818
// It serves as a receiver for unmarshaling processes and for that reason
1919
// its types are kept simple (certain types are incompatible with certain
2020
// unmarshalers).
2121
// It exposes a method Unmarshal to convert its values into a runner.Config.
22-
type Representation struct {
22+
type representation struct {
2323
Extends *string `yaml:"extends" json:"extends"`
2424

2525
Request struct {
@@ -49,14 +49,14 @@ type Representation struct {
4949
} `yaml:"tests" json:"tests"`
5050
}
5151

52-
func (repr Representation) validate() error {
53-
return repr.Into(&benchttp.Runner{})
52+
func (repr representation) validate() error {
53+
return repr.parseAndMutate(&benchttp.Runner{})
5454
}
5555

56-
// Into parses the Representation receiver as a benchttp.Runner
56+
// parseAndMutate parses the Representation receiver as a benchttp.Runner
5757
// and stores any non-nil field value into the corresponding field
5858
// of dst.
59-
func (repr Representation) Into(dst *benchttp.Runner) error {
59+
func (repr representation) parseAndMutate(dst *benchttp.Runner) error {
6060
if err := repr.parseRequestInto(dst); err != nil {
6161
return err
6262
}
@@ -66,7 +66,7 @@ func (repr Representation) Into(dst *benchttp.Runner) error {
6666
return repr.parseTestsInto(dst)
6767
}
6868

69-
func (repr Representation) parseRequestInto(dst *benchttp.Runner) error {
69+
func (repr representation) parseRequestInto(dst *benchttp.Runner) error {
7070
if dst.Request == nil {
7171
dst.Request = &http.Request{}
7272
}
@@ -103,7 +103,7 @@ func (repr Representation) parseRequestInto(dst *benchttp.Runner) error {
103103
return nil
104104
}
105105

106-
func (repr Representation) parseRunnerInto(dst *benchttp.Runner) error {
106+
func (repr representation) parseRunnerInto(dst *benchttp.Runner) error {
107107
if requests := repr.Runner.Requests; requests != nil {
108108
dst.Requests = *requests
109109
}
@@ -139,7 +139,7 @@ func (repr Representation) parseRunnerInto(dst *benchttp.Runner) error {
139139
return nil
140140
}
141141

142-
func (repr Representation) parseTestsInto(dst *benchttp.Runner) error {
142+
func (repr representation) parseTestsInto(dst *benchttp.Runner) error {
143143
testSuite := repr.Tests
144144
if len(testSuite) == 0 {
145145
return nil
@@ -254,7 +254,7 @@ func requireConfigFields(fields map[string]interface{}) error {
254254
return nil
255255
}
256256

257-
type representations []Representation
257+
type representations []representation
258258

259259
// mergeInto successively parses the given representations into dst.
260260
//
@@ -265,7 +265,7 @@ func (reprs representations) mergeInto(dst *benchttp.Runner) error {
265265
}
266266

267267
for _, repr := range reprs {
268-
if err := repr.Into(dst); err != nil {
268+
if err := repr.parseAndMutate(dst); err != nil {
269269
return errorutil.WithDetails(ErrFileParse, err)
270270
}
271271
}

configio/yaml.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// UnmarshalYAML parses the YAML-encoded data and stores the result
1616
// in the Representation pointed to by dst.
17-
func UnmarshalYAML(in []byte, dst *Representation) error {
17+
func UnmarshalYAML(in []byte, dst *representation) error {
1818
dec := NewYAMLDecoder(bytes.NewReader(in))
1919
return dec.Decode(dst)
2020
}
@@ -35,7 +35,7 @@ func NewYAMLDecoder(r io.Reader) YAMLDecoder {
3535

3636
// Decode reads the next YAML-encoded value from its input
3737
// and stores it in the Representation pointed to by dst.
38-
func (d YAMLDecoder) Decode(dst *Representation) error {
38+
func (d YAMLDecoder) Decode(dst *representation) error {
3939
decoder := yaml.NewDecoder(d.r)
4040
decoder.KnownFields(true)
4141
return d.handleError(decoder.Decode(dst))
@@ -44,11 +44,11 @@ func (d YAMLDecoder) Decode(dst *Representation) error {
4444
// Decode reads the next YAML-encoded value from its input
4545
// and stores it in the benchttp.Runner pointed to by dst.
4646
func (d YAMLDecoder) DecodeRunner(dst *benchttp.Runner) error {
47-
repr := Representation{}
47+
repr := representation{}
4848
if err := d.Decode(&repr); err != nil {
4949
return err
5050
}
51-
return repr.Into(dst)
51+
return repr.parseAndMutate(dst)
5252
}
5353

5454
// handleError handles a raw yaml decoder.Decode error, filters it,

0 commit comments

Comments
 (0)