Building from Source
Building from Source
Section titled “Building from Source”Build Alita Robot from source for development, customization, or when pre-built binaries are not available for your platform.
Prerequisites
Section titled “Prerequisites”| Tool | Minimum Version | Purpose |
|---|---|---|
| Go | 1.25+ | Compilation |
| Git | 2.0+ | Clone repository |
| Make | Any | Build automation |
| golangci-lint | Latest | Code quality checks |
Install Go
Section titled “Install Go”# macOSbrew install go
# Ubuntu/Debiansudo snap install go --classic
# Or download from https://go.dev/dl/Install golangci-lint
Section titled “Install golangci-lint”# macOSbrew install golangci-lint
# Linux/macOS via scriptcurl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
# Go installgo install github.com/golangci/golangci-lint/cmd/golangci-lint@latestClone the Repository
Section titled “Clone the Repository”git clone https://github.com/divkix/Alita_Robot.gitcd Alita_RobotBuild Commands
Section titled “Build Commands”Development Build
Section titled “Development Build”Run the bot directly from source:
# Using Makemake run
# Or using Go directlygo run main.goProduction Build
Section titled “Production Build”Build optimized release binaries using GoReleaser:
# Install GoReleasergo install github.com/goreleaser/goreleaser@latest
# Buildmake buildThis creates binaries in the dist/ directory for all supported platforms.
Manual Build
Section titled “Manual Build”Build for your current platform:
go build -o alita_robot .Build with optimizations:
go build -ldflags="-s -w" -o alita_robot .Cross-compile for other platforms:
# Linux amd64GOOS=linux GOARCH=amd64 go build -o alita_robot_linux_amd64 .
# macOS arm64GOOS=darwin GOARCH=arm64 go build -o alita_robot_darwin_arm64 .
# Windows amd64GOOS=windows GOARCH=amd64 go build -o alita_robot_windows_amd64.exe .Makefile Targets
Section titled “Makefile Targets”| Target | Command | Description |
|---|---|---|
run | make run | Run the bot from source |
build | make build | Build release binaries with GoReleaser |
lint | make lint | Run golangci-lint for code quality |
tidy | make tidy | Clean and download go.mod dependencies |
vendor | make vendor | Vendor dependencies |
psql-migrate | make psql-migrate | Apply database migrations |
psql-status | make psql-status | Check migration status |
psql-reset | make psql-reset | Reset database (DANGEROUS) |
Code Quality
Section titled “Code Quality”Run Linter
Section titled “Run Linter”make lintThis runs golangci-lint with the project’s configuration. Fix any issues before committing.
Check Dependencies
Section titled “Check Dependencies”make tidyThis:
- Removes unused dependencies
- Downloads missing dependencies
- Updates
go.sumchecksums
Project Structure
Section titled “Project Structure”Alita_Robot/├── main.go # Entry point├── go.mod # Go module definition├── go.sum # Dependency checksums├── Makefile # Build automation├── .goreleaser.yaml # GoReleaser configuration├── sample.env # Example environment file├── docker-compose.yml # Docker Compose configuration├── alita/ # Main application code│ ├── config/ # Configuration loading│ ├── db/ # Database models and operations│ ├── modules/ # Bot command handlers│ ├── utils/ # Utility functions│ ├── i18n/ # Internationalization│ └── health/ # Health check handlers├── migrations/ # SQL migration files├── locales/ # Translation files└── docs/ # DocumentationDevelopment Mode
Section titled “Development Mode”For development, run with debug logging:
DEBUG=true make runOr set in your .env file:
DEBUG=trueDebug mode:
- Increases log verbosity
- Disables performance monitoring
- Shows detailed error stack traces
GoReleaser Configuration
Section titled “GoReleaser Configuration”The .goreleaser.yaml defines the build process:
version: 2project_name: alita_robot
builds: - binary: alita_robot env: - CGO_ENABLED=0 goos: - darwin - linux - windows goarch: - amd64 - arm64 flags: - -trimpath ldflags: - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}}Build Output
Section titled “Build Output”After running make build, binaries are created in:
dist/├── alita_robot_linux_amd64/│ └── alita_robot├── alita_robot_linux_arm64/│ └── alita_robot├── alita_robot_darwin_amd64/│ └── alita_robot├── alita_robot_darwin_arm64/│ └── alita_robot├── alita_robot_windows_amd64/│ └── alita_robot.exe└── checksums.txtDependencies
Section titled “Dependencies”Key dependencies from go.mod:
| Package | Purpose |
|---|---|
gotgbot/v2 | Telegram Bot API client |
gorm.io/gorm | ORM for database operations |
go-redis/v9 | Redis client |
sirupsen/logrus | Structured logging |
spf13/viper | Configuration management |
sentry-go | Error tracking |
prometheus/client_golang | Metrics |
Testing
Section titled “Testing”While the project primarily uses golangci-lint for quality checks:
# Run linter (recommended before commits)make lint
# Test manually with a test botDEBUG=true make runHot Reload (Development)
Section titled “Hot Reload (Development)”Use air for automatic reloading during development:
# Install airgo install github.com/air-verse/air@latest
# Create .air.tomlair init
# Run with hot reloadairExample .air.toml:
root = "."tmp_dir = "tmp"
[build]cmd = "go build -o ./tmp/alita_robot ."bin = "tmp/alita_robot"include_ext = ["go"]exclude_dir = ["tmp", "vendor", "docs"]Contributing
Section titled “Contributing”- Fork the repository
- Create a feature branch
- Make changes
- Run
make lintand fix any issues - Submit a pull request
See Contributing Guide for more details.
Troubleshooting
Section titled “Troubleshooting”Go version too old
Section titled “Go version too old”go: go.mod requires go >= 1.25Update Go to version 1.25 or higher.
golangci-lint not found
Section titled “golangci-lint not found”# Install golangci-lintgo install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Add to PATHexport PATH=$PATH:$(go env GOPATH)/binModule download errors
Section titled “Module download errors”# Clear module cachego clean -modcache
# Download dependenciesmake tidyBuild fails with CGO errors
Section titled “Build fails with CGO errors”The bot is built with CGO_ENABLED=0 for static binaries. If you need CGO:
CGO_ENABLED=1 go build -o alita_robot .Note: CGO requires C compiler and platform-specific libraries.