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.
NoteUsing 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)
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
APP_NAME="gFly - Web framework"
APP_CODE="gfly"
APP_ENV=prod
APP_URL=http://localhost:7789
APP_DEBUG=true
- Parameter
APP_NAMEis simply the application name you need to set. - Parameter
APP_CODEis simply the application code you need to set. - Parameter
APP_ENVis 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_DEBUGhelps to run a corresponding process for development and debugging purposes. Valuetrueis not recommended in production environments (When APP_ENV isprod). - Parameter
APP_URLshould be a public URL value.
SERVER_HOST="0.0.0.0"
SERVER_PORT=7789
- The default
SERVER_HOSTparameter is0.0.0.0so the application can accept requests from anywhere. - Parameter
SERVER_PORTdefault port7789.
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
STATIC_PATH=public
Static resource will put into folder ./public/. To serve static files such as images, CSS, JavaScript and HTML files, and more.
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_VERSIONis the way to know the current version. - Parameter
API_NAMEto help label the API document.
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_DEBUGto help log out something from database. - Parameter
DB_HOSTis the Database server value. - Parameter
DB_PORTis the Database port value. - Parameter
DB_NAMEis the Database name value. - Pair parameters
DB_USERNAMEandDB_PASSWORDis credentials to connect to Database. - Parameters
DB_SSL_MODE,DB_MAX_CONNECTION,DB_MAX_IDLE_CONNECTION,DB_MAX_LIFETIME_CONNECTION, andDB_MAX_IDLE_TIME_CONNECTIONcome from libgithub.com/jmoiron/sqlx. Refer SQLX
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_PROTOCOLissmtp. The default protocol for mailing in gFly. - Parameter
MAIL_HOSTis Mail host. - Parameter
MAIL_PORTis Mail port number. - Pair parameters
MAIL_USERNAMEandMAIL_PASSWORDis credentials to connect to Mail server. - Parameter
MAIL_SENDERis sender’s email for all mail sent out. - Parameter
MAIL_NAMEis the sender’s email name. - Parameter
MAIL_TLSis a SMTP option.
REDIS_HOST="redis"
REDIS_PORT=6379
REDIS_PASSWORD=secret
REDIS_DEFAULT_DB=1
REDIS_SESSION_DB=0
REDIS_QUEUE_DB=1
- Parameter
REDIS_HOSTis Redis server. - Parameter
REDIS_PORTis Redis port number. - Parameter
REDIS_PASSWORDis Redis password. - Parameter
REDIS_DEFAULT_DBis DB number. - Parameter
REDIS_SESSION_DBis Web Session number. Note: gFly support session viaRedisorMemory. - Parameter
REDIS_QUEUE_NUMBERis DB number for Queue system. Note: gFly only support queue via Redis.
SESSION_TYPE=redis
SESSION_KEY=gfly_session
SESSION_TTL=30
SESSION_ID=gflyid
- Parameter
SESSION_TYPEhas value""if you want to disable session. gFly supports 2 session storagesmemoryandredis. - Parameter
SESSION_KEYis session key. It helps to us easy to monitor session data when useredisstorage. - Parameter
SESSION_TTLis Time To Live for a user’s session. Unit is minute. - Parameter
SESSION_IDis cookie name related to session.
VIEW_PATH=./resources/views
VIEW_EXT=tpl
- Parameter
VIEW_PATHis folder to store template files. - Parameter
VIEW_EXTis extension of template file. Value istpl.
STORAGE_DIR=storage
APP_DIR=storage/app
LOG_DIR=storage/logs
TEMP_DIR=storage/tmp
- Parameter
STORAGE_DIRis folder to store file. - Parameter
LOG_DIRis folder to store log file. - Parameter
APP_DIRis folder to store app file. - Parameter
TEMP_DIRis folder to store temporary file.
# NOTE: Log settings:
# - Trace|Debug|Info|Warn|Error|Fatal|Panic
LOG_CHANNEL=file
LOG_FILE=logs.log
LOG_LEVEL=Trace
- Parameter
LOG_CHANNELis log channel. Only supportfilechannel. - Parameter
LOG_FILEis log file format. - Parameter
LOG_LEVELis log level.
# FILESYSTEM_TYPE:
# - "local" Local storage (Default).
# - "s3" S3 storage.
FILESYSTEM_TYPE=local
- Parameter
FILESYSTEM_TYPEis folder to store template files. gFly supports 2 file storageslocalands3.
NOTIFICATION_ENABLE=true
- Parameter
NOTIFICATION_ENABLEto enable or disable notification.