Skip to content

Commit 14a5aff

Browse files
authored
[easy] make yaml, json, toml specific functions be private in cuecfg (#115)
## Summary These should be private for this package. External callers should invoke `cuecfg.Marshal` and `cuecfg.Unmarshal` ## How was it tested? compiles
1 parent 4543cfc commit 14a5aff

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

cuecfg/cuecfg.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@ func Marshal(valuePtr any, extension string) ([]byte, error) {
2121

2222
switch extension {
2323
case ".json":
24-
return MarshalJSON(valuePtr)
24+
return marshalJSON(valuePtr)
2525
case ".yml", ".yaml":
26-
return MarshalYaml(valuePtr)
26+
return marshalYaml(valuePtr)
2727
case ".toml":
28-
return MarshalToml(valuePtr)
28+
return marshalToml(valuePtr)
2929
}
3030
return nil, errors.Errorf("Unsupported file format '%s' for config file", extension)
3131
}
3232

3333
func Unmarshal(data []byte, extension string, valuePtr any) error {
3434
switch extension {
3535
case ".json":
36-
err := UnmarshalJSON(data, valuePtr)
36+
err := unmarshalJSON(data, valuePtr)
3737
if err != nil {
3838
return errors.WithStack(err)
3939
}
4040
return nil
4141
case ".yml", ".yaml":
42-
err := UnmarshalYaml(data, valuePtr)
42+
err := unmarshalYaml(data, valuePtr)
4343
if err != nil {
4444
return errors.WithStack(err)
4545
}
4646
return nil
4747
case ".toml":
48-
err := UnmarshalToml(data, valuePtr)
48+
err := unmarshalToml(data, valuePtr)
4949
if err != nil {
5050
return errors.WithStack(err)
5151
}

cuecfg/json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import "encoding/json"
88
// TODO: consider using cue's JSON marshaller instead of
99
// "encoding/json" ... it might have extra functionality related
1010
// to the cue language.
11-
func MarshalJSON(v interface{}) ([]byte, error) {
11+
func marshalJSON(v interface{}) ([]byte, error) {
1212
return json.MarshalIndent(v, "", " ")
1313
}
1414

15-
func UnmarshalJSON(data []byte, v interface{}) error {
15+
func unmarshalJSON(data []byte, v interface{}) error {
1616
return json.Unmarshal(data, v)
1717
}

cuecfg/toml.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"github.com/pelletier/go-toml/v2"
88
)
99

10-
func MarshalToml(v interface{}) ([]byte, error) {
10+
func marshalToml(v interface{}) ([]byte, error) {
1111
return toml.Marshal(v)
1212
}
1313

14-
func UnmarshalToml(data []byte, v interface{}) error {
14+
func unmarshalToml(data []byte, v interface{}) error {
1515
return toml.Unmarshal(data, v)
1616
}

cuecfg/yaml.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import "gopkg.in/yaml.v3"
88
// TODO: consider using cue's YAML marshaller.
99
// It might have extra functionality related
1010
// to the cue language.
11-
func MarshalYaml(v interface{}) ([]byte, error) {
11+
func marshalYaml(v interface{}) ([]byte, error) {
1212
return yaml.Marshal(v)
1313
}
1414

15-
func UnmarshalYaml(data []byte, v interface{}) error {
15+
func unmarshalYaml(data []byte, v interface{}) error {
1616
return yaml.Unmarshal(data, v)
1717
}

0 commit comments

Comments
 (0)