mconfig

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VerboseLogging bool = false

If verbose logging is enabled

Functions

func DefaultDatabaseName

func DefaultDatabaseName(profile string, databaseName string) string

Get the default database name for a database.

func DefaultPassword

func DefaultPassword(dbType DatabaseType) string

Get the default password for a database by type.

func DefaultUsername

func DefaultUsername(dbType DatabaseType) string

Get the default username for a database by type.

func EverythingToSnakeCase

func EverythingToSnakeCase(s string) string

Convert every character except for letters and digits directly to _

Types

type Context

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

func DefaultContext

func DefaultContext(appName string, profile string) *Context

func (*Context) AddDatabase

func (c *Context) AddDatabase(database *Database)

Add a new database.

func (*Context) AppName

func (c *Context) AppName() string

The app name you set in your config.

func (*Context) ApplyPlan

func (c *Context) ApplyPlan(plan *Plan)

Apply a plan for the environment in the config

func (*Context) Databases

func (c *Context) Databases() []*Database

Get the databases.

func (*Context) Environment

func (c *Context) Environment() *Environment

func (*Context) LoadSecretsToEnvironment

func (c *Context) LoadSecretsToEnvironment(path string) error

Note: In case you use a relative path, expect it to start in the Magic directory.

func (*Context) NewPostgresDatabase

func (c *Context) NewPostgresDatabase(name string) *Database

func (*Context) Plan

func (c *Context) Plan() *Plan

Plan for later (DO NOT EXPECT THIS TO BE FILLED BEFORE DEPLOYMENT STEP)

func (*Context) Ports

func (c *Context) Ports() []uint

func (*Context) Profile

func (c *Context) Profile() string

The current profile.

test = Test profile. default = Default profile. You can set the profile by passing the --m-profile flag to the executable that includes magic.

func (*Context) ValuePort

func (c *Context) ValuePort(preferredPort uint) EnvironmentValue

Allocate a new port for the container (and parse it as a environment variable).

func (*Context) WithEnvironment

func (c *Context) WithEnvironment(env Environment)

Set the environment.

type Database

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

func (*Database) DatabaseName

func (db *Database) DatabaseName(ctx *Context) EnvironmentValue

Get the name of the database for environment variables

func (*Database) DefaultDatabaseName

func (db *Database) DefaultDatabaseName(ctx *Context) string

Get the default name for the database using the runner

func (*Database) DefaultPassword

func (db *Database) DefaultPassword() string

Get the default password for the database type

func (*Database) DefaultUsername

func (db *Database) DefaultUsername() string

Get the default username for the database type

func (*Database) Host

func (db *Database) Host(ctx *Context) EnvironmentValue

Get the host of the database for environment variables

func (*Database) Name

func (db *Database) Name() string

Get the name of the database (as in the config)

func (*Database) Password

func (db *Database) Password() EnvironmentValue

Get the password of the database for environment variables

func (*Database) Port

func (db *Database) Port(ctx *Context) EnvironmentValue

Get the port of the database for environment variables

func (*Database) Type

func (db *Database) Type() DatabaseType

func (*Database) Username

func (db *Database) Username() EnvironmentValue

Get the username of the database for environment variables

type DatabaseType

type DatabaseType = uint
const (
	DatabasePostgres DatabaseType = 1
)

type Environment

type Environment map[string]EnvironmentValue

func (*Environment) Generate

func (e *Environment) Generate() map[string]string

Apply all the environment variables

type EnvironmentValue

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

func ValueStatic

func ValueStatic(value string) EnvironmentValue

Create a new static environment value.

func ValueWithBase

func ValueWithBase(values []EnvironmentValue, builder func([]string) string) EnvironmentValue

Create a new environment value based on other environment values.

The index in the values array matches the output of the environment value.

type Plan

type Plan struct {
	AppName        string                `json:"app_name"`
	Profile        string                `json:"profile"`
	Environment    map[string]string     `json:"environment"`
	DatabaseTypes  []PlannedDatabaseType `json:"database_types"`
	AllocatedPorts map[uint]uint         `json:"ports"`
}

func FromPrintable

func FromPrintable(printable string) (*Plan, error)

Convert back to a plan from printable form

func (*Plan) Database

func (p *Plan) Database(name string) PlannedDatabase

Get a database by its name. Panics when it can't find the database.

func (*Plan) ToPrintable

func (p *Plan) ToPrintable() (string, error)

Turn the plan into printable form

type PlannedDatabase

type PlannedDatabase struct {
	Name     string `json:"name"`
	Username string `json:"username"`
	Password string `json:"password"`
	Hostname string `json:"hostname"`

	// Just for developers to access, not included in actual plan
	Type DatabaseType `json:"-"`
	Port uint         `json:"-"`
}

func (PlannedDatabase) ConnectString

func (db PlannedDatabase) ConnectString() string

Generate a connection string for the database.

type PlannedDatabaseType

type PlannedDatabaseType struct {
	Port      uint              `json:"port"`
	Type      DatabaseType      `json:"type"`
	Databases []PlannedDatabase `json:"databases"`
}

func (*PlannedDatabaseType) ContainerName

func (p *PlannedDatabaseType) ContainerName(appName string, profile string) string

Name for the database Docker container

Jump to

Keyboard shortcuts

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