Configuration
Learn how to configure Gophel for your specific project needs.
Overview
Gophel uses a combination of configuration files, environment variables, and command-line flags to customize its behavior. This flexible approach allows you to configure Gophel for different environments and workflows.
The gophel.yaml
file is the primary way to configure your Gophel projects.
Use environment variables to override configuration settings or provide sensitive information.
Command-line flags provide the highest precedence for configuration options.
The gophel.yaml Configuration File
The gophel.yaml
file is located in the root of your project and contains all the configuration options for your application. It's divided into several sections for different aspects of your application.
# Basic project information
name: my-go-app
version: 1.0.0
description: "A sample Go application managed by Gophel"
# Project metadata
author: "Your Name"
license: "MIT"
repository: "https://github.com/username/my-go-app"
# Go version requirement
go_version: "1.18"
Key Fields
name
- The name of your application (required)version
- The current version of your applicationdescription
- A brief description of your applicationgo_version
- The minimum Go version required for your application
Environment Variables
Gophel supports environment variables for configuration. These can be used to override settings in thegophel.yaml
file or to provide sensitive information that shouldn't be stored in version control.
Variable | Description | Example |
---|---|---|
GOPHEL_CONFIG | Path to the configuration file | ./config/gophel.yaml |
GOPHEL_ENV | Current environment (development, production, etc.) | production |
GOPHEL_PORT | Default port for applications | 3000 |
GOPHEL_LOG_LEVEL | Log level for Gophel itself | debug |
GOPHEL_AUTH_TOKEN | Authentication token for Gophel monitoring panel | abc123def456 |
Note: You can also define application-specific environment variables in therun.env
section of yourgophel.yaml
file.
Configuration Precedence
When multiple configuration sources define the same setting, Gophel follows this precedence order (from highest to lowest):
- Command-line flags
- Environment variables
- Environment-specific configuration in
gophel.yaml
- Default configuration in
gophel.yaml
- Gophel built-in defaults
Example of Configuration Precedence
If you set the port in multiple places:
- Command:
gophel build myApp --port 5000
- Environment:
GOPHEL_PORT=4000
- Config file:
run.port: 3000
The port 5000 will be used because command-line flags have the highest precedence.
Configuration Best Practices
Follow these guidelines to maintain a clean and effective configuration:
Never store sensitive information like API keys, database passwords, or tokens in yourgophel.yaml
file. Use environment variables instead.
Use the environments
section to define settings for different environments (development, staging, production).
Keep your gophel.yaml
file in version control, but create a gophel.local.yaml
for local overrides that should not be committed.
Add comments to your configuration file to explain non-obvious settings and why certain values were chosen.
Next Steps
Now that you understand how to configure Gophel, you might want to explore: