config

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultPerm fs.FileMode = 0666

DefaultPerm defines the default file permissions (0666) for created config files.

Variables

View Source
var CommentSuffix = "______"

CommentSuffix defines the special suffix used to identify comment-like keys. Keys ending with this suffix will be treated as comments and converted to actual '#'(YAML) comments in output.

Functions

func List

func List() []string

List returns a list of all registered migration drivers.

func New

func New(driver Driver, cfg Settings) database.Driver

New returns a new instance of the config driver using the given settings.

func Open

func Open(url string) (database.Driver, error)

Open returns a new instance of a migration database driver using the given URL.

func Register

func Register(name string, driver Driver, cfg Settings)

Register globally registers a new config driver with the specified name and settings.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config represents the core struct used to manage config-based migrations. It contains a driver for reading/writing config data and a locked file to prevent concurrent access.

func (*Config) Close

func (m *Config) Close() error

Close closes the locked file if open.

func (*Config) Drop

func (m *Config) Drop() error

Drop resets the config file by truncating it and writing empty/default content.

func (*Config) Lock

func (m *Config) Lock() error

Lock opens the file with locking and stores the handle for later operations.

func (*Config) Open

func (m *Config) Open(filePath string) (database.Driver, error)

Open sets the file path from a URL and returns the current instance.

func (*Config) Run

func (m *Config) Run(migration io.Reader) error

Run applies a migration by reading the migration data and merging it with existing config data.

func (*Config) SetVersion

func (m *Config) SetVersion(version int, dirty bool) error

SetVersion updates the current config file with version and dirty (force) flags.

func (*Config) Unlock

func (m *Config) Unlock() error

Unlock releases the mutex and closes the locked file.

func (*Config) Version

func (m *Config) Version() (int, bool, error)

Version reads and returns the current migration version and dirty flag.

type Driver

type Driver interface {
	// Unmarshal — deserializes data from []byte into a map.
	Unmarshal([]byte, interface{}) error

	// Marshal — serializes a map into []byte.
	Marshal(interface{}, bool) ([]byte, error)

	// Version — extracts the version number from the data.
	Version([]byte) (int, bool, error)

	// EmptyData — returns the default empty data content.
	EmptyData() []byte
}

Driver is the interface that every config driver must implement.

type Settings

type Settings struct {
	// Path — the path to the configuration file.
	Path string

	// Perm — file permissions for reading/writing the config file.
	Perm fs.FileMode

	// UnableToReplaceComments True if some comments could be replaced
	UnableToReplaceComments bool
}

Settings represents the configuration settings for a config driver.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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