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.

Configuration File

The gophel.yaml file is the primary way to configure your Gophel projects.

Environment Variables

Use environment variables to override configuration settings or provide sensitive information.

Command-line Flags

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 Configuration
Core settings for your Gophel project
# 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 application
  • description - A brief description of your application
  • go_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.

Gophel Environment Variables
Environment variables that control Gophel's behavior
VariableDescriptionExample
GOPHEL_CONFIGPath to the configuration file./config/gophel.yaml
GOPHEL_ENVCurrent environment (development, production, etc.)production
GOPHEL_PORTDefault port for applications3000
GOPHEL_LOG_LEVELLog level for Gophel itselfdebug
GOPHEL_AUTH_TOKENAuthentication token for Gophel monitoring panelabc123def456

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

  1. Command-line flags
  2. Environment variables
  3. Environment-specific configuration in gophel.yaml
  4. Default configuration in gophel.yaml
  5. 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:

Use Environment Variables for Secrets

Never store sensitive information like API keys, database passwords, or tokens in yourgophel.yaml file. Use environment variables instead.

Create Environment-Specific Configurations

Use the environments section to define settings for different environments (development, staging, production).

Use Version Control

Keep your gophel.yaml file in version control, but create a gophel.local.yaml for local overrides that should not be committed.

Document Your Configuration

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: