Source Code Deployment

Build and deploy GPT-Load from source code, suitable for developers to customize and debug features. Provides complete control and flexibility.

Environment Requirements

Development Environment

Requires local installation of Go development environment and related toolchain

Required Software

  • Go 1.23+ development environment
  • Git version control tool
  • Make build tool
  • Database service (MySQL/PostgreSQL/SQLite)

Optional Software

  • Redis cache service
  • Node.js and npm (for frontend development)
  • Docker (for containerized testing)
  • IDE or editor (VS Code/GoLand)

Installation Steps

1

Clone Source Code

Clone GPT-Load source code repository from GitHub:

git clone https://github.com/tbphp/gpt-load.git
cd gpt-load

TipIf you need a specific version, use git checkout v1.x.x to switch to the corresponding version tag

2

Install Dependencies

Download and install Go module dependencies:

go mod tidy

NoteEnsure network connection is stable, some dependencies may need to be downloaded from overseas servers

3

Database Configuration

Create Configuration File

cp .env.example .env

Copy example configuration file and modify according to your environment

Database Connection Configuration

SQLite (recommended for development)

DATABASE_DSN=./data/gpt-load.db

MySQL

DATABASE_DSN=root:123456@tcp(mysql:3306)/gpt-load?charset=utf8mb4&parseTime=True&loc=Local

PostgreSQL

DATABASE_DSN=postgres://postgres:123456@postgres:5432/gpt-load?sslmode=disable
4

Build and Run

Build Frontend

cd web && npm install && npm run build

Run Backend Development Service

go run main.go

Run Frontend Development Service

cd web && npm run dev

Development Guide

Project Structure

gpt-load/
  ├── internal/ # Internal business logic
  │    ├── app/ # Application initialization
  │    ├── channel/ # Channel type management
  │    ├── config/ # Configuration management
  │    ├── container/ # Dig container service management
  │    ├── db/ # DB initialization and migration scripts
  │    ├── errors/ # Error messages
  │    ├── handler/ # Management API interfaces
  │    ├── httpclient/ # HTTP client wrapper
  │    ├── keypool/ # Key pool management
  │    ├── middleware/ # Middleware
  │    ├── models/ # Data models
  │    ├── proxy/ # Proxy service
  │    ├── response/ # Response wrapper
  │    ├── router/ # Routing
  │    ├── services/ # Business logic layer
  │    ├── store/ # Unified memory
  │    ├── syncer/ # Cluster synchronizer
  │    ├── types/ # Type definitions
  │    └── version/ # Version constants
  ├── web/ # Frontend resources
  ├── go.mod # Go module definition
  ├── .env.example # Configuration example
  ├── docker-compose.yml # Configuration example
  ├── Dockerfile # Configuration example
  ├── Makefile # Build rules
  └── main.go # Entry program

Troubleshooting

Common Issues

Go version too low

Error messagego version go1.xx.x: minimum supported version is go1.23

SolutionUpgrade Go version to 1.23 or higher

Dependency download failed

Possible causes: network connection issues or proxy settings

# Set Go proxy
go env -w GOPROXY=https://goproxy.cn,direct

Next Steps

After source code deployment is complete, you can:

  • Deeply understand code structure and customize features
  • Participate in open source projects and submit Pull Requests
  • Build custom Docker images
  • Integrate into CI/CD pipelines