Skip to main content

Project Setup

This guide walks you through creating a new Go project that uses Gate from scratch. If you prefer a pre-configured setup, see the Plugin Template instead.

Prerequisites

Before you begin, ensure you have:
  • Go 1.21 or higher installed (download here)
  • Basic Go knowledge (modules, packages, functions)
  • A text editor (VS Code, GoLand, Vim, etc.)
  • Terminal access for running commands
Verify your Go installation:

Creating a New Project

1

Create Project Directory

Create a new directory for your project:
2

Initialize Go Module

Initialize a new Go module:
Replace github.com/yourusername/my-gate-proxy with your actual module path.
3

Add Gate Dependency

Add Gate as a dependency:
This will download Gate and update your go.mod file.
4

Create Main File

Create a main.go file with the following content:
5

Create Configuration File

Create a config.yml file for Gate’s configuration:
This configures Gate to:
  • Listen on port 25565
  • Connect players to the “lobby” server first
  • Fall back to other servers if lobby is unavailable
6

Download Dependencies

Download all module dependencies:
7

Build and Run

Build and run your proxy:
You should see output indicating Gate has started:

Project Structure

A typical Gate project structure:

Understanding go.mod

After running go get, your go.mod should look like:
Key dependencies you’ll commonly use:
  • go.minekube.com/gate - Core proxy functionality
  • go.minekube.com/brigodier - Command framework
  • go.minekube.com/common - Minecraft components (chat, colors)
  • github.com/robinbraemer/event - Event system

Adding Common Features

Register a Command

Create commands.go:
Update main.go to call it:

Handle Events

Create events.go:
Update main.go:

Working with Components

Gate uses a component system for rich text:

Complete Example

Here’s a complete main.go with commands and events:

Building Your Project

Development Build

For quick testing:

Production Build

Create an optimized binary:

Cross-Compilation

Build for different platforms:

Configuration Best Practices

Separate Environments

Create different config files for different environments:
Run with a specific config:

Environment Variables

Use environment variables for sensitive data:

Validation

Gate validates your configuration on startup. Common issues:

Troubleshooting

Error: go: module go.minekube.com/gate: Get "https://proxy.golang.org/..." failedSolutions:
  1. Check your internet connection
  2. Verify firewall isn’t blocking Go module proxy
  3. Try setting GOPROXY environment variable:
Error: import cycle not allowedSolution: Reorganize your code to avoid circular imports. For example:
Error: bind: address already in useSolutions:
  1. Find and stop the process using the port:
  2. Or change the port in config.yml:
Error: config file not foundSolution: Ensure config.yml is in the same directory as your binary:
Or specify the path explicitly:
Error: Players can’t connect to backend serversSolutions:
  1. Verify backend servers are running:
  2. Check firewall rules allow connections
  3. Verify addresses in config.yml are correct
  4. Check backend server logs for connection attempts

Testing Your Proxy

Manual Testing

  1. Start your proxy:
  2. Start a backend server (e.g., Paper, Spigot) on port 25566
  3. Connect with Minecraft client to localhost:25565

Unit Testing

Create main_test.go:
Run tests:

Performance Tips

Use Goroutines for Async Operations

Batch Player Operations

Resource Cleanup

Use context cancellation:

Next Steps

Commands Guide

Learn how to create powerful commands

Events Guide

Master the event system

Simple Proxy Example

Study a complete working example

API Reference

Explore the full API documentation

Additional Resources