This commit is contained in:
wenyifan
2026-06-28 13:48:48 +08:00
parent b139ed5968
commit 7eb0be458e
2 changed files with 16 additions and 0 deletions
+2
View File
@@ -39,6 +39,7 @@ var (
apiAddr string
metricsAddr string
reload time.Duration
showConfig bool
)
func init() {
@@ -102,6 +103,7 @@ func init() {
flag.StringVar(&apiAddr, "api", "", "api service address")
flag.StringVar(&metricsAddr, "metrics", "", "metrics service address")
flag.DurationVar(&reload, "R", 0, "auto reload period (e.g. 30s, 1m)")
flag.BoolVar(&showConfig, "P", false, "print config only")
flag.Parse()
if printVersion {
+14
View File
@@ -2,7 +2,9 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"os/signal"
@@ -23,6 +25,7 @@ import (
metrics "github.com/go-gost/x/metrics/service"
"github.com/go-gost/x/registry"
"github.com/judwhite/go-svc"
"gopkg.in/yaml.v3"
)
type program struct {
@@ -90,6 +93,17 @@ func (p *program) run(cfg *config.Config) error {
svc.Serve()
}()
}
if showConfig {
if outputFormat == "json" {
marshal, _ := json.Marshal(cfg)
fmt.Println(string(marshal))
} else {
marshal, _ := yaml.Marshal(cfg)
fmt.Println(string(marshal))
}
os.Exit(0)
return nil
}
if p.srvApi != nil {
p.srvApi.Close()