Skip to content

Commit 4ace975

Browse files
authored
feat: add config subcommand to generate default config files (minekube#608)
* feat: add config subcommand to generate default config files - Add 'gate config' subcommand to output default configuration templates - Support multiple config types: full, minimal, simple, lite, bedrock - Add --write flag to write directly to config.yml - Embed config files using go:embed for distribution - Add sync-configs Makefile target and go:generate directives - Update documentation with config generation examples and templates * docs: update quick-start guide for configuration file generation - Change wording from "default configuration file" to "simple configuration file" for clarity. - Update command example to reflect the new syntax for generating a simple configuration file with the `-t simple -w` flags. * docs: update configuration menu item text for clarity - Changed menu item text from "Complete Configuration" to "Configuration & Templates" to better reflect the content.
1 parent fb7d2a8 commit 4ace975

12 files changed

Lines changed: 762 additions & 6 deletions

File tree

.web/docs/.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export default defineConfig({
199199
text: 'Configuration',
200200
items: [
201201
{
202-
text: '📋 Complete Configuration',
202+
text: '📋 Configuration & Templates',
203203
link: '/guide/config/',
204204
},
205205
{

.web/docs/guide/config/index.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,61 @@
11
---
2-
title: "Gate Configuration Guide - Proxy Settings"
3-
description: "Configure Gate Minecraft proxy with YAML settings, server routes, authentication, and advanced proxy features."
2+
title: 'Gate Configuration Guide - Proxy Settings'
3+
description: 'Configure Gate Minecraft proxy with YAML settings, server routes, authentication, and advanced proxy features.'
44
---
55

66
# Configuration
77

8-
```yaml config.yml
8+
Gate uses a YAML configuration file (`config.yml`) to configure all proxy settings.
9+
10+
## Config File Location
11+
12+
Gate looks for `config.yml` in the current working directory by default. Use `--config` or `-c` to specify a custom path:
13+
14+
```sh console
15+
$ gate # Uses ./config.yml
16+
$ gate -c /path/to/config.yml
17+
```
18+
19+
Gate supports YAML (`.yml`, `.yaml`), JSON (`.json`), and environment variables with `GATE_` prefix. You can mix formats - use a config file and override values with environment variables.
20+
21+
## Configuration Templates
22+
23+
Generate configuration files using the `gate config` command, or create them manually:
24+
25+
```sh console
26+
# Write to config.yml
27+
$ gate config --write
28+
$ gate config --type <type> --write
29+
30+
# Write to custom file using pipe redirection
31+
$ gate config > my-config.yml
32+
$ gate config --type <type> > my-config.yml
33+
```
34+
35+
You can also create the `config.yml` file manually using any of the templates below as a starting point.
36+
37+
::: code-group
38+
39+
```yaml [Full (default)]
940
<!--@include: ../../../../config.yml -->
1041
```
42+
43+
```yaml [Simple]
44+
<!--@include: ../../../../config-simple.yml -->
45+
```
46+
47+
```yaml [Lite]
48+
<!--@include: ../../../../config-lite.yml -->
49+
```
50+
51+
```yaml [Bedrock]
52+
<!--@include: ../../../../config-bedrock.yml -->
53+
```
54+
55+
```yaml [Minimal]
56+
<!--@include: ../../../../internal/configs/config-minimal.yml -->
57+
```
58+
59+
:::
60+
61+
For most users, the full configuration is recommended. You can generate it and then edit the `servers` section to point to your backend Minecraft servers.

.web/docs/guide/quick-start.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ Gate supports:
7676

7777
Gate connects to your Minecraft servers and forwards client connections to them.
7878

79-
You can do this by creating and editing the `config.yml` file.
79+
You can generate a simple configuration file using:
80+
81+
```sh console
82+
$ gate config -t simple -w
83+
```
84+
85+
Then edit the `config.yml` file to configure your backend servers:
8086

8187
```yaml config.yml
8288
<!--@include: ../../../config-simple.yml -->

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
all: fmt vet mod lint
22

3+
# Sync embedded config files from root directory
4+
sync-configs:
5+
cp config.yml internal/configs/config.yml
6+
cp config-simple.yml internal/configs/config-simple.yml
7+
cp config-lite.yml internal/configs/config-lite.yml
8+
cp config-bedrock.yml internal/configs/config-bedrock.yml
9+
# Note: config-minimal.yml is maintained directly in internal/configs, not synced from root
10+
311
# Build Gate with version information
4-
build:
12+
build: sync-configs
513
@VERSION=$$(git describe --tags --always --dirty 2>/dev/null || echo "dev-$$(git rev-parse --short HEAD 2>/dev/null || echo unknown)") && \
614
echo "Building Gate version: $$VERSION" && \
715
go build -ldflags="-s -w -X 'go.minekube.com/gate/pkg/version.Version=$$VERSION'" -o gate gate.go

cmd/gate/config.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package gate
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/urfave/cli/v2"
8+
"go.minekube.com/gate/internal/configs"
9+
)
10+
11+
func configCommand() *cli.Command {
12+
return &cli.Command{
13+
Name: "config",
14+
Usage: "Output default configuration file",
15+
Description: `Output the default configuration file to stdout or a file.
16+
You can redirect to a file or use the --write flag:
17+
18+
gate config > config.yml
19+
gate config --write # Writes to config.yml
20+
21+
Available config types:
22+
- full (default): Full configuration with all options
23+
- minimal: Empty/minimal configuration (uses all defaults)
24+
- simple: Minimal configuration example with servers
25+
- lite: Lite mode configuration example
26+
- bedrock: Bedrock cross-play configuration example`,
27+
Flags: []cli.Flag{
28+
&cli.StringFlag{
29+
Name: "type",
30+
Aliases: []string{"t"},
31+
Usage: "Config type: full, minimal, simple, lite, or bedrock",
32+
Value: "full",
33+
},
34+
&cli.BoolFlag{
35+
Name: "write",
36+
Aliases: []string{"w"},
37+
Usage: "Write config to config.yml instead of stdout",
38+
},
39+
},
40+
Action: func(c *cli.Context) error {
41+
configType := c.String("type")
42+
var configBytes []byte
43+
44+
switch configType {
45+
case "full":
46+
configBytes = configs.DefaultConfigBytes
47+
case "minimal":
48+
configBytes = configs.MinimalConfigBytes
49+
case "simple":
50+
configBytes = configs.SimpleConfigBytes
51+
case "lite":
52+
configBytes = configs.LiteConfigBytes
53+
case "bedrock":
54+
configBytes = configs.BedrockConfigBytes
55+
default:
56+
return cli.Exit(fmt.Sprintf("unknown config type: %s (valid types: full, minimal, simple, lite, bedrock)", configType), 1)
57+
}
58+
59+
if c.Bool("write") {
60+
outputFile := "config.yml"
61+
err := os.WriteFile(outputFile, configBytes, 0644)
62+
if err != nil {
63+
return cli.Exit(fmt.Errorf("error writing config to %q: %w", outputFile, err), 1)
64+
}
65+
fmt.Printf("Configuration written to %s\n", outputFile)
66+
return nil
67+
}
68+
69+
_, err := os.Stdout.Write(configBytes)
70+
if err != nil {
71+
return cli.Exit(fmt.Errorf("error writing config: %w", err), 1)
72+
}
73+
74+
return nil
75+
},
76+
}
77+
}

cmd/gate/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func App() *cli.App {
4949
5050
Visit the website https://gate.minekube.com/ for more information.`
5151

52+
app.Commands = []*cli.Command{
53+
configCommand(),
54+
}
55+
5256
var (
5357
debug bool
5458
configFile string
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
config:
2+
bind: 0.0.0.0:25565
3+
onlineMode: true
4+
servers:
5+
server1: 0.0.0.0:25566
6+
try:
7+
- server1
8+
# forwarding:
9+
# mode: legacy
10+
# velocitySecret: 'bedrock-crossplay-secret'
11+
status:
12+
motd: |
13+
§bGate + Geyser Cross-Play
14+
§eJava & Bedrock Players Welcome!
15+
16+
# Enable Bedrock edition support
17+
bedrock:
18+
managed: true
19+
# Geyser will connect to this address that Gate listens on in parallel to the bind address.
20+
# localhost is recommended for same-machine setups (use 0.0.0.0 for Docker Compose)
21+
geyserListenAddr: 'localhost:25567'
22+
# Username format for Bedrock players to avoid conflicts
23+
usernameFormat: '.%s'
24+
# Path to Floodgate key for authentication
25+
floodgateKeyPath: '.examples/bedrock/geyser/key.pem'

internal/configs/config-lite.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# This is a simplified config where the rest of the
2+
# settings are omitted and will be set by default.
3+
# See config.yml for the full configuration options.
4+
config:
5+
# The bind address to listen for Minecraft client connections.
6+
bind: 0.0.0.0:25565
7+
# Lite mode is a lightweight reverse proxy mode that acts as thin layer between the client and the backend server.
8+
# Full documentation: https://gate.minekube.com/guide/lite
9+
#
10+
# It efficiently routes client connections based on the virtual host address received in the handshake packet.
11+
# This allows to protect multiple backend servers behind a single port Gate Lite proxy instance.
12+
# Player connections (including ping requests and player authentication) is forwarded to the destined backend server.
13+
# This means Lite mode supports proxy behind proxy setups, but advanced features like server switching or proxy commands are no longer available
14+
# and have no effect in Lite mode when extensions use higher level Gate APIs and events.
15+
lite:
16+
# Enable Lite mode.
17+
# If disabled, the proxy will act as a full proxy with all features enabled just like BungeeCord/Velocity.
18+
# If enabled, the proxy will act as a lightweight reverse proxy to support new types of deployment architecture.
19+
# Default: false
20+
enabled: true
21+
# The routes that the proxy redirects player connections to based on matching the virtual host address.
22+
# The routes are matched in order of appearance.
23+
# Examples:
24+
routes:
25+
# Match the virtual host address to the backend server.
26+
- host: localhost
27+
# The backend server to connect to if matched.
28+
backend: localhost:25566
29+
# The optional fallback status response when all backends of this route are offline.
30+
fallback:
31+
motd: |
32+
§cLocalhost server is offline.
33+
§eCheck back later!
34+
version:
35+
name: '§cTry again later!'
36+
protocol: -1
37+
#players:
38+
# online: 0
39+
# max: 1000
40+
# The optional favicon to show in the server list (optimal 64x64).
41+
# Accepts a path of an image file or the base64 data uri.
42+
favicon: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5AgJCgs6JBZy0AAAB+lJREFUeNrtmGuMXVUZht/LOvcz7diWklbJaKGCWKXFUiiBQjAEhRSLSCEqIKAiogRTmiriBeSiUUhjMCZe2qQxNE0EUZSCidAgYMBSLBJCDC1taAg4xaq1cz/788feZzqgocCoP2Q/f87JOXvvfOtd73dZGygpKSkpKSkpKSkpKSkpKSkpKSkpKXnzwNd7w+ULD0NEBtmQBFqQBNuIC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uAJdTugTAoUWcOwDsLcJ6GMAyAMsLUWYCGAWwragLGwtnYNIOAICbLz4DKe0/0R13+hI8fv+jDVlJ0miWZUOykZLHT3sUQRAUUa3X8OGrvotf3bqyRYlOaSCyLJvoIjIPpd5uoG/uO/DcMzu743i1iHOsk3U6BMffPnXPbEUdyCJigOTL3htM6jD0Sr53+VmQ07gQ432aQiBQq9cAomhdQgBo9bQg7x+eim6AyDJUm00gAikRlLCvswc9noZqT6uozvGyELvvRI5ddhUeufM7ebcgX/k+BXwNCy8pKSkpKSkpKSkpKSkpKSkpKSkpKXkz8k8RHxEbZN/8lgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMC0wOC0wOVQxMDoxMTo0MyswMDowMN6nNEYAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjAtMDgtMDlUMTA6MTE6NDMrMDA6MDCv+oz6AAAAAElFTkSuQmCC
43+
# You can also use * wildcard to match any subdomain.
44+
- host: '*.example.com'
45+
backend: 172.16.0.12:25566
46+
proxyProtocol: true # Use proxy protocol to connect to backend.
47+
tcpShieldRealIP: true # Optionally you can also use TCPShield's RealIP protocol.
48+
# Use hostname parameters in backend addresses with $1, $2, etc.
49+
# Example: abc.domain.com → abc.servers.svc:25565
50+
- host: '*.domain.com'
51+
backend: '$1.servers.svc:25565'
52+
# You can also match to multiple hosts to one or multiple backends.
53+
- host: [127.0.0.1, localhost]
54+
backend: [172.16.0.12:25566, backend.example.com:25566]
55+
# Load balancing strategy when multiple backends are available.
56+
# See https://gate.minekube.com/guide/lite#load-balancing-strategies for detailed guide.
57+
# Options: sequential, random, round-robin, least-connections, lowest-latency
58+
# Default: sequential (tries backends in config order)
59+
# strategy: random # Uncomment to use random instead of sequential
60+
# Ping responses are cached per backend address by default.
61+
# To disable motd caching set it to -1.
62+
# Default: 10s
63+
cachePingTTL: 60s
64+
# Modifies the virtual host to match the backend address in the handshake request.
65+
# This is useful when backends require players to connect with a specific domain.
66+
# Lite will modify the player's handshake packet's virtual host field from `localhost` -> `backend.example.com`
67+
# before forwarding the connection to the backend.
68+
# Default: false
69+
modifyVirtualHost: true
70+
# Match all as last item routes any other host to a default backend.
71+
- host: '*'
72+
backend: 10.0.0.10:25565
73+
fallback:
74+
motd: §eNo server available for this host.
75+
version:
76+
name: §eTry example.com
77+
protocol: -1
78+
#players:
79+
# online: 0
80+
# max: 1000
81+
#favicon: server-icon.png
82+
83+
# The follow settings from standard Gate also apply to Lite mode.
84+
#
85+
# The time Gate waits to connect to a server before timing out.
86+
connectionTimeout: 5s
87+
# The time Gate waits to receive data from a server before timing out.
88+
# If you use Forge, you may need to increase this setting.
89+
readTimeout: 30s
90+
# Enabled extra debug logging (only for debugging purposes).
91+
debug: false
92+
# Proxy protocol (HA-Proxy) determines whether Gate should support proxy protocol for players.
93+
# Do not enable this if you don't know what it is.
94+
proxyProtocol: false
95+
# The quota settings allows rate-limiting IP (last block cut off) for certain operations.
96+
# ops: The allowed operations per second.
97+
# burst: The maximum operations per second (queue like). One burst unit per seconds is refilled.
98+
# maxEntries: The maximum IPs to keep track of in cache for rate-limiting (if full, deletes oldest).
99+
quota:
100+
# Limit how many new connections can be established by the same IP range.
101+
connections:
102+
enabled: true
103+
ops: 5
104+
burst: 10
105+
maxEntries: 1000
106+
107+
# Configuration for Connect, a network that organizes all Minecraft servers/proxies
108+
# and makes them universally accessible for all players.
109+
# Among a lot of other features it even allows players to join locally hosted
110+
# Minecraft servers without having an open port or public IP address.
111+
#
112+
# Visit https://connect.minekube.com/
113+
connect:
114+
# Enabling Connect makes Gate register itself to Connect network.
115+
# This feature is disabled by default, but you are encouraged to
116+
# enable it and get empowered by the additional network services
117+
# and by the growing community in this ecosystem.
118+
enabled: false
119+
# The endpoint name is a globally unique identifier of your server.
120+
# If Connect is enabled, but no name is specified a random name is
121+
# generated on every restart (only recommended for testing).
122+
#
123+
# It is supported to run multiple Gates on the same endpoint name for load balancing
124+
# (use the same connect.json token file from first Gate instance).
125+
#name: your-endpoint-name
126+
127+
# Gate HTTP API configuration.
128+
# See https://gate.minekube.com/guide/api for more information.
129+
api:
130+
# Whether to enable the API for Gate.
131+
# Default: false
132+
enabled: false
133+
# The bind address to listen for API connections.
134+
# Default: localhost:8080
135+
bind: localhost:8080
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Minimal Gate configuration
2+
# All other settings will use their default values
3+
config: {}

internal/configs/config-simple.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This is a simplified config where the rest of the
2+
# settings are omitted and will be set by default.
3+
# See config.yml for the full configuration options.
4+
config:
5+
bind: 0.0.0.0:25565
6+
servers:
7+
server1: localhost:25566
8+
server2: localhost:25567
9+
try:
10+
- server1
11+
- server2

0 commit comments

Comments
 (0)