Build Management

Streamline the process of building and compiling your Go applications.

Overview

Gophel's build management features simplify the process of compiling Go applications, handling dependencies, and preparing your code for execution. With automated Go installation, cross-platform support, and customizable build options, Gophel makes building Go applications faster and more reliable.

Simplified Building

Build your Go applications with a single command, without worrying about complex build flags or environment setup.

Automated Setup

Gophel automatically installs and configures the required Go version if it's not already on your system.

The Build Command

The gophel build command is the primary way to build your Go applications.

gophel build
Builds and starts your Go application

Syntax

gophel build <NAME> --port <PORT>

Parameters

  • <NAME> - The name of your application
  • --port <PORT> - (Optional) The port to run your application on. Default is 8080

Example

gophel build myApp --port 3000

Output

Building application 'myApp', ID: 82572e1cc66419e8
Application 'myApp' (ID: 82572e1cc66419e8) started successfully on port 3000

Rebuilding Applications

When you make changes to your code, you can use the gophel rebuild command to recompile and restart your application.

gophel rebuild
Rebuilds and restarts an application

Syntax

gophel rebuild <ID> --port <PORT>

Parameters

  • <ID> - The ID of the application to rebuild
  • --port <PORT> - (Optional) The port to run your application on. If not specified, the previously used port will be used

Example

gophel rebuild 82572e1cc66419e8 --port 3000

Output

Rebuilding application 82572e1cc66419e8
Application 'myApp' (ID: 82572e1cc66419e8) stopped successfully
Rebuilding application 'myApp'
Application 'myApp' (ID: 82572e1cc66419e8) rebuilt and started successfully on port 3000

Build Configuration

You can customize the build process by configuring the build section in your gophel.yaml file.

Basic Build Configuration
Essential build settings
# Build configuration
build:
  # Main entry point
  main: "./cmd/app/main.go"
  
  # Output binary path
  output: "./bin/app"
  
  # Build flags passed to 'go build'
  flags:
    - "-ldflags=-s -w"

Key Fields

  • main - The path to your main Go file (required)
  • output - The path where the compiled binary will be placed
  • flags - Additional flags to pass to the Go build command

Build Best Practices

Follow these guidelines for efficient builds:

  • Use -ldflags="-s -w" to reduce binary size
  • Set CGO_ENABLED=0 for static binaries
  • Include version information in your builds with -ldflags="-X main.Version=v1.0.0"
  • Use pre-build commands for code generation and validation
  • Enable build caching for faster rebuilds during development

Next Steps

Now that you understand Gophel's build management features, you might want to explore: