Skip to main content
gFly v1.15.1
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage
Edit page

Configuration

Configuration parameters are set in the .env file. Their use should be via the os.Getenv() function. However, there is also a generic function utils.Getenv() from module "github.com/gflydev/core/utils" that differs from the utilities in terms of default value.

Note

Using utils.Getenv() will help you immediately get the data type you need. No additional conversion operations are required. Examples:

  • Get string utils.Getenv("REDIS_HOST", "localhost")
  • Get number utils.Getenv("REDIS_PORT", 6379)
  • Get boolean utils.Getenv("NOTIFICATION_ENABLE", false)
  • Get float utils.Getenv("NOTIFICATION_ENABLE", 0.0)

File .env

When you first start with gFly. You only need to care about the two available files .env.example used for running gFly directly locally. They have their own initial settings to help you run application. However, they are still a completely identical set of parameters, as follows:

# NOTE: Application settings:
# APP_ENV:
#   - "local" Local env
#   - "dev" Dev env
#   - "stag" Staging env
#   - "prod" Production env
APP_NAME="gFly - Web framework"
APP_CODE="gfly"
APP_ENV=prod
APP_URL=http://localhost:7789
APP_DEBUG=true

# NOTE: Server settings:
SERVER_HOST="0.0.0.0"
SERVER_PORT=7789

# NOTE: TLS settings:
SERVER_TLS_CERT=
SERVER_TLS_KEY=

# NOTE: Static settings:
STATIC_PATH=public

# NOTE: Log settings:
#   - Trace|Debug|Info|Warn|Error|Fatal|Panic
LOG_CHANNEL=file
LOG_FILE=logs.log
LOG_LEVEL=Trace

# NOTE: API settings:
API_PREFIX=api
API_VERSION=v1
API_NAME="gFly API"

# NOTE: Database settings:
DB_DEBUG=true
DB_HOST="localhost"
DB_PORT=5432
DB_NAME="gfly"
DB_USERNAME="user"
DB_PASSWORD="secret"
DB_SSL_MODE="disable"
DB_MAX_CONNECTION=100
DB_MAX_IDLE_CONNECTION=10
DB_MAX_LIFETIME_CONNECTION=30
DB_MAX_IDLE_TIME_CONNECTION=3

# NOTE: Mail settings:
MAIL_PROTOCOL=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=user
MAIL_PASSWORD=secret
MAIL_SENDER=no-reply@jivecode.com
MAIL_NAME="gFly - No Reply"
MAIL_TLS=true

# NOTE: Redis settings:
REDIS_HOST="localhost"
REDIS_PORT=6379
REDIS_PASSWORD=secret
REDIS_DEFAULT_DB=1
REDIS_SESSION_DB=0
# REDIS_QUEUE_DB=1

# NOTE: Session setting:
#   SESSION_TTL minutes
SESSION_KEY=gfly
SESSION_TTL=30
SESSION_ID=gflyid

# NOTE: View Template settings:
VIEW_PATH=resources/views
VIEW_EXT=tpl

# NOTE: Storage file system settings:
STORAGE_DIR=storage
APP_DIR=storage/app
LOG_DIR=storage/logs
TEMP_DIR=storage/tmp

# NOTE: Default Storage settings:
# FILESYSTEM_TYPE:
#   - "local" Local storage (Default).
#   - "s3" S3 storage.
FILESYSTEM_TYPE=local

# NOTE: Notification settings:
NOTIFICATION_ENABLE=true

Parameters Application settings

APP_NAME="gFly - Web framework"
APP_CODE="gfly"
APP_ENV=prod
APP_URL=http://localhost:7789
APP_DEBUG=true
  • Parameter APP_NAME is simply the application name you need to set.
  • Parameter APP_CODE is simply the application code you need to set.
  • Parameter APP_ENV is the current environment in which the application is running. Currently, there are 4 environments you can choose from: local, dev, stag, prod. Note: Accurately recording running environments will help perform application functions and support and management tools correctly.
  • Parameter APP_DEBUG helps to run a corresponding process for development and debugging purposes. Value true is not recommended in production environments (When APP_ENV is prod).
  • Parameter APP_URL should be a public URL value.

Parameters Server settings

SERVER_HOST="0.0.0.0"
SERVER_PORT=7789
  • The default SERVER_HOST parameter is 0.0.0.0 so the application can accept requests from anywhere.
  • Parameter SERVER_PORT default port 7789.

Parameters TLS settings

SERVER_TLS_CERT=./resources/tls/localhost.crt
SERVER_TLS_KEY=./resources/tls/localhost.key

To support SSL at the local env, we have made available TLS files.

For Mac environment. You should run the following to add a trusted certificate to Mac.

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain localhost.crt

Disable TLS by setting EMPTY values:

SERVER_TLS_CERT=
SERVER_TLS_KEY=

If you want to create a new TLS. Please check at Create SSL

Parameters Static settings

STATIC_PATH=public

Static resource will put into folder ./public/. To serve static files such as images, CSS, JavaScript and HTML files, and more.

Parameters API settings

API_PREFIX=api
API_VERSION=v1
API_NAME="gFly API"
  • If the application serves both Web and API. So, we need the prefix API parameter API_PREFIX.
  • Many API versions can be used in the application. So, we need to indicate that the parameter API_VERSION is the way to know the current version.
  • Parameter API_NAME to help label the API document.

Parameters Database settings

DB_DEBUG=true
DB_HOST="localhost"
DB_PORT=5432
DB_NAME="gfly"
DB_USERNAME="user"
DB_PASSWORD="secret"
DB_SSL_MODE="disable"
DB_MAX_CONNECTION=100
DB_MAX_IDLE_CONNECTION=10
DB_MAX_LIFETIME_CONNECTION=30
DB_MAX_IDLE_TIME_CONNECTION=3
  • Parameter DB_DEBUG to help log out something from database.
  • Parameter DB_HOST is the Database server value.
  • Parameter DB_PORT is the Database port value.
  • Parameter DB_NAME is the Database name value.
  • Pair parameters DB_USERNAME and DB_PASSWORD is credentials to connect to Database.
  • Parameters DB_SSL_MODE, DB_MAX_CONNECTION, DB_MAX_IDLE_CONNECTION, DB_MAX_LIFETIME_CONNECTION, and DB_MAX_IDLE_TIME_CONNECTION come from lib github.com/jmoiron/sqlx. Refer SQLX

Parameters Mail settings

MAIL_PROTOCOL=smtp
MAIL_HOST=mail
MAIL_PORT=1025
MAIL_USERNAME=user
MAIL_PASSWORD=secret
MAIL_SENDER=no-reply@gfly.dev
MAIL_NAME="gFly - No Reply"
MAIL_TLS=true
  • Parameter MAIL_PROTOCOL is smtp. The default protocol for mailing in gFly.
  • Parameter MAIL_HOST is Mail host.
  • Parameter MAIL_PORT is Mail port number.
  • Pair parameters MAIL_USERNAME and MAIL_PASSWORD is credentials to connect to Mail server.
  • Parameter MAIL_SENDER is sender’s email for all mail sent out.
  • Parameter MAIL_NAME is the sender’s email name.
  • Parameter MAIL_TLS is a SMTP option.

Parameters Redis settings

REDIS_HOST="redis"
REDIS_PORT=6379
REDIS_PASSWORD=secret
REDIS_DEFAULT_DB=1
REDIS_SESSION_DB=0
REDIS_QUEUE_DB=1
  • Parameter REDIS_HOST is Redis server.
  • Parameter REDIS_PORT is Redis port number.
  • Parameter REDIS_PASSWORD is Redis password.
  • Parameter REDIS_DEFAULT_DB is DB number.
  • Parameter REDIS_SESSION_DB is Web Session number. Note: gFly support session via Redis or Memory.
  • Parameter REDIS_QUEUE_NUMBER is DB number for Queue system. Note: gFly only support queue via Redis.

Parameters Session settings

SESSION_TYPE=redis
SESSION_KEY=gfly_session
SESSION_TTL=30
SESSION_ID=gflyid
  • Parameter SESSION_TYPE has value "" if you want to disable session. gFly supports 2 session storages memory and redis.
  • Parameter SESSION_KEY is session key. It helps to us easy to monitor session data when use redis storage.
  • Parameter SESSION_TTL is Time To Live for a user’s session. Unit is minute.
  • Parameter SESSION_ID is cookie name related to session.

Parameters View template settings

VIEW_PATH=./resources/views
VIEW_EXT=tpl
  • Parameter VIEW_PATH is folder to store template files.
  • Parameter VIEW_EXT is extension of template file. Value is tpl.

Parameters Storage file system settings

STORAGE_DIR=storage
APP_DIR=storage/app
LOG_DIR=storage/logs
TEMP_DIR=storage/tmp
  • Parameter STORAGE_DIR is folder to store file.
  • Parameter LOG_DIR is folder to store log file.
  • Parameter APP_DIR is folder to store app file.
  • Parameter TEMP_DIR is folder to store temporary file.

Parameters Log settings


# NOTE: Log settings:
#   - Trace|Debug|Info|Warn|Error|Fatal|Panic
LOG_CHANNEL=file
LOG_FILE=logs.log
LOG_LEVEL=Trace
  • Parameter LOG_CHANNEL is log channel. Only support file channel.
  • Parameter LOG_FILE is log file format.
  • Parameter LOG_LEVEL is log level.

Parameters File system settings

# FILESYSTEM_TYPE:
#   - "local" Local storage (Default).
#   - "s3" S3 storage.
FILESYSTEM_TYPE=local
  • Parameter FILESYSTEM_TYPE is folder to store template files. gFly supports 2 file storages local and s3.

Parameters Notification settings

NOTIFICATION_ENABLE=true
  • Parameter NOTIFICATION_ENABLE to enable or disable notification.