Configuration

Learn how to configure your Dracory application for different environments.

Configuration

All of the configuration files for the Dracory framework are stored in the config directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you.

Environment Configuration

It is often helpful to have different configuration values based on the environment where the application is running. For example, you may wish to use a different database locally than you do on your production server.

To make this a cinch, Dracory utilizes the .env file. A .env.example file is included with the framework, which contains common environment variables. During the Dracory installation process, this file will automatically be copied to .env.

You should typically run the config:cache command as part of your production deployment routine. The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.

# .env example
APP_NAME=Dracory
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=dracory
DB_USERNAME=root
DB_PASSWORD=

Configuration Files

Dracory's configuration files are located in the config directory. These files allow you to configure things like your database connection information, mail server information, as well as various other core configuration values such as your application timezone and encryption key.

App Configuration

The config/app.go file contains several options such as the application name and timezone.

// config/app.go
package config

const (
	AppName = "Dracory"
	AppEnv  = "local"
	AppKey  = "your-secret-key"
	AppDebug = true
	AppUrl  = "http://localhost:8080"
)

Database Configuration

The config/database.go file contains configuration for your database connections, and supports several database systems out of the box, including MySQL, PostgreSQL, and SQLite.

// config/database.go
package config

const (
	DBConnection = "sqlite"
	DBHost       = "127.0.0.1"
	DBPort       = "3306"
	DBDatabase   = "dracory"
	DBUsername   = "root"
	DBPassword   = ""
)

Accessing Configuration Values

You can easily access configuration values within your application using the config package:

import "project/config"

// Get the application name
appName := config.AppName

Configuration Caching

To give your application a speed boost, you can cache all of your configuration files into a single file using the config:cache command:

go run main.go config:cache

You should typically run the config:cache command as part of your production deployment routine. The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.

Menu