Skip to content

Commit 20792d7

Browse files
committed
configmigrate: imp naming
1 parent 998929a commit 20792d7

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

internal/configmigrate/migrator.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (m *Migrator) Run(ctx context.Context, target SchemaVersion) (err error) {
6161
confPath := filepath.Join(m.workingDir, m.configName)
6262
logger := m.logger.With("config_path", confPath)
6363

64-
conf, err := readYobj(confPath)
64+
conf, err := readYAML(confPath)
6565
if err != nil {
6666
if errors.Is(err, fs.ErrNotExist) {
6767
logger.DebugContext(ctx, "configuration file does not exist")
@@ -96,7 +96,7 @@ func (m *Migrator) Run(ctx context.Context, target SchemaVersion) (err error) {
9696
}
9797

9898
// getVersion returns the schema version from the configuration object.
99-
func (m *Migrator) getVersion(conf yobj) (v SchemaVersion, err error) {
99+
func (m *Migrator) getVersion(conf yObj) (v SchemaVersion, err error) {
100100
verInt, err := fieldVal[int](conf, SchemaVersionKey)
101101
if err != nil {
102102
return 0, err
@@ -112,11 +112,11 @@ func (m *Migrator) getVersion(conf yobj) (v SchemaVersion, err error) {
112112
}
113113

114114
// migrateFunc is a function that upgrades conf or returns an error.
115-
type migrateFunc = func(ctx context.Context, conf yobj) (err error)
115+
type migrateFunc = func(ctx context.Context, conf yObj) (err error)
116116

117117
// migrate performs migrations from current schema version to the target one.
118118
// It returns an error from the first failed migration.
119-
func (m *Migrator) migrate(ctx context.Context, conf yobj, curr, targ SchemaVersion) (err error) {
119+
func (m *Migrator) migrate(ctx context.Context, conf yObj, curr, targ SchemaVersion) (err error) {
120120
migrations := [VersionLatest]migrateFunc{
121121
// There is obviously no migration to the initial version.
122122
0: nil,
@@ -186,7 +186,7 @@ func (m *Migrator) backupConfig(
186186
func (m *Migrator) writeMigrated(
187187
ctx context.Context,
188188
l *slog.Logger,
189-
conf yobj,
189+
conf yObj,
190190
origPath string,
191191
curr SchemaVersion,
192192
targ SchemaVersion,

internal/configmigrate/v2.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ import (
3333
// # …
3434
// # …
3535
// schema_version: 2
36-
func (m *Migrator) migrateTo2(ctx context.Context, conf yobj) (err error) {
36+
func (m *Migrator) migrateTo2(ctx context.Context, conf yObj) (err error) {
3737
const target SchemaVersion = 2
3838

39-
dnsVal, err := fieldVal[yobj](conf, "dns")
39+
dnsVal, err := fieldVal[yObj](conf, "dns")
4040
if err != nil {
4141
// Don't wrap the error since it's informative enough as is.
4242
return err
4343
}
4444

45-
serverVal, err := fieldVal[yobj](dnsVal, "server")
45+
serverVal, err := fieldVal[yObj](dnsVal, "server")
4646
if err != nil {
4747
// Don't wrap the error since it's informative enough as is.
4848
return err
@@ -56,7 +56,7 @@ func (m *Migrator) migrateTo2(ctx context.Context, conf yobj) (err error) {
5656
return fmt.Errorf("%s: %w", key, errors.ErrNotEmpty)
5757
}
5858

59-
serverVal[key] = yobj{
59+
serverVal[key] = yObj{
6060
"enabled": true,
6161
"interval": timeutil.Duration(1 * time.Second),
6262
"count": 4,

internal/configmigrate/yaml.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99
"gopkg.in/yaml.v3"
1010
)
1111

12-
// yobj is the convenience alias for YAML key-value object.
13-
type yobj = map[string]any
12+
// yObj is the convenience alias for YAML key-value object.
13+
type yObj = map[string]any
1414

1515
// fieldVal returns the value of type T for key from obj. It returns errors if
1616
// the key is not found, the value is not set, or the value is not of type T.
17-
func fieldVal[T any](obj yobj, key string) (v T, err error) {
17+
func fieldVal[T any](obj yObj, key string) (v T, err error) {
1818
val, ok := obj[key]
1919
if !ok {
2020
return v, fmt.Errorf("%s: %w", key, errors.ErrNoValue)
@@ -32,9 +32,9 @@ func fieldVal[T any](obj yobj, key string) (v T, err error) {
3232
return v, nil
3333
}
3434

35-
// readYobj reads the YAML file from filePath and returns the parsed YAML
35+
// readYAML reads the YAML file from filePath and returns the parsed YAML
3636
// object.
37-
func readYobj(filePath string) (obj yobj, err error) {
37+
func readYAML(filePath string) (obj yObj, err error) {
3838
// #nosec G304 -- Trust the file path since it's constant now.
3939
f, err := os.Open(filePath)
4040
if err != nil {

0 commit comments

Comments
 (0)