mconfig

package module
v0.0.0-...-bbfa983 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2025 License: Apache-2.0 Imports: 8 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDatabaseName

func DefaultDatabaseName(config string, 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 _

func IsValidDatabaseType

func IsValidDatabaseType(t DatabaseType) bool

Types

type Context

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

func DefaultContext

func DefaultContext(module string, config string, profile string, magicDir string) *Context

func (*Context) AddDatabase

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

Add a new database.

func (*Context) ApplyPlan

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

Apply a plan for the environment in the config

func (*Context) Config

func (c *Context) Config() string

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) Module

func (c *Context) Module() string

func (*Context) Plan

func (c *Context) Plan() *Plan

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

func (*Context) Profile

func (c *Context) Profile() string

func (*Context) WithEnvironment

func (c *Context) WithEnvironment(env *Environment)

Set the environment.

type Database

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

func NewPostgresDatabase

func NewPostgresDatabase(name string) *Database

Create a new Postgres database.

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.

type Plan

type Plan struct {
	Environment   map[string]string     `json:"environment"`
	DatabaseTypes []PlannedDatabaseType `json:"database_types"`
}
var CurrentPlan *Plan = nil

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, error)

Get a database by its name.

func (*Plan) ToPrintable

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

Turn the plan into printable form

type PlannedDatabase

type PlannedDatabase struct {
	ConfigName string `json:"config_name"` // Name in the config
	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(modName string, config 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