minekube / gate

High-Performance, Low-Memory, Lightweight, Extensible Minecraft Reverse Proxy with Excellent Multi-Protocol Version Support - Velocity/Bungee Replacement - Ready for dev and large deploy!
https://gate.minekube.com
Apache License 2.0
584 stars 50 forks source link

Enhance writing Gate config for external programs (fixes #325, closes #327) #328

Closed robinbraemer closed 2 months ago

robinbraemer commented 2 months ago

example program that can now rewrite the gate config seamlessly:

package main

import (
    liteconfig "go.minekube.com/gate/pkg/edition/java/lite/config"
    "go.minekube.com/gate/pkg/gate/config"
    "go.minekube.com/gate/pkg/util/configutil"
    "gopkg.in/yaml.v3"
    "os"
)

func main() {
    cfg := config.Config{}
    f, err := os.ReadFile("config.yml")
    if err != nil {
        panic(err)
    }
    err = yaml.Unmarshal(f, &cfg)
    if err != nil {
        panic(err)
    }
    cfg.Editions = config.Editions{} // empty it
    cfg.Config.Lite.Routes = append(cfg.Config.Lite.Routes, liteconfig.Route{
        Host:    configutil.SingleOrMulti[string]{"localhost"},
        Backend: []string{"localhost"},
    })
    out, err := yaml.Marshal(cfg)
    if err != nil {
        panic(err)
    }
    err = os.WriteFile("config.yml", out, 0644)
    if err != nil {
        panic(err)
    }
}
cloudflare-pages[bot] commented 2 months ago

Deploying gate-minekube with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8510b15
Status: ✅  Deploy successful!
Preview URL: https://0345ebad.gate-minekube.pages.dev
Branch Preview URL: https://fix-config.gate-minekube.pages.dev

View logs