upmig1

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package upmig1 provides configuration file settings upwards Migrator for settings major version 1 and its Adapter type for the version independent repo.UpMigrator[migrationuc.Settings] interface.

This package provides the main logic for converting settings with major version 1 format to major version 2.

The settings.UpMigrator generic interface is employed in order to ensure that this version-specific implementation uses consistent types as its method return types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapt

Adapt creates an instance of Adapter struct wraping the `m` argument. Because Adapter expects to wrap a Type instance, it asserts that Migrator struct implements the Type interface, its implementation is correct (considering the expected return types), and provides the repo.UpMigrator[migrationuc.Settings] interface.

func NewUpMig

NewUpMig creates a Migrator struct wrapping the given Config instance and then uses the Adapt function in order to adapt it to the version independent repo.UpMigrator[migrationuc.Settings] interface.

The Migrator struct is exported and users which need a concrete type can create it directly and wrap the `c` instance. This helper New function is provided in order to combine these two steps (of creation and adaptation) together.

Types

type Adapter

type Adapter struct {
	T Type
}

Adapter wraps and adapts an instance of Type in order to provide the repo.UpMigrator[migrationuc.Settings] interface.

func (Adapter) MigrateUp

func (a Adapter) MigrateUp(ctx context.Context) (
	repo.UpMigrator[migrationuc.Settings], error,
)

MigrateUp calls the wrapped Type MigrateUp method, obtains the next upwards migrator object, and adapts it to the version-independent repo.UpMigrator[migrationuc.Settings] interface using the Adapt function.

func (Adapter) Settler

func (a Adapter) Settler() migrationuc.Settings

Settler calls the wrapped Type Settler method, obtains a C instance, and wraps it by settings.Adapter[C, S] in order to expose an instance of migrationuc.Settings interface.

type C

type C = *cfg1.Config

C is the underlying Config type

type Migrator

type Migrator struct {
	*cfg1.Config
}

Migrator is an upwards Config migrator for *cfg1.Config instances. It wraps a Config struct (with major version 1) and implements the repo.Settler and pkg/adapter/config/settings.UpMigrator generic interfaces.

func (*Migrator) MigrateUp

func (m *Migrator) MigrateUp(
	_ context.Context,
) (*upmig2.Migrator, error)

MigrateUp creates a *cfg2.Config instance and fills it with the settings which are kept in `m.Config` fields. Any field which its value may not be computed based on the settings which are available in this version will be left uninitialized. The computed Config instance with major version 2 will be wrapped by its corresponding upwards migrator before being returned.

func (*Migrator) Settler

func (m *Migrator) Settler() *cfg1.Config

Settler returns the wrapped Config object. After migrating from a source Config version upwards and reaching to an ultimate version, this method reveals the final migrated Config object. This object may have some uninitialized settings too. The MergeConfig method may be used in order to fill them from another Config instance containing the default settings for major version 1.

type S added in v1.2.0

type S = cfg1.Serializable

S is the Serializable struct type containing mutable settings

type Type

type Type = settings.UpMigrator[C, S, *upmig2.Migrator]

Type is implemented by the Migrator type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL