From ceefa5b5c81380dc3230875514956d06de566cfd Mon Sep 17 00:00:00 2001 From: fsl <1171313930@qq.com> Date: Sun, 21 Jul 2024 18:58:25 +0800 Subject: [PATCH] fix: Unified variable management Signed-off-by: fsl <1171313930@qq.com> --- .../golang/v4/scaffolds/internal/templates/main.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/main.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/main.go index 7f0fa141456..250ecca50e9 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/main.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/main.go @@ -221,11 +221,14 @@ func init() { } func main() { - var metricsAddr string - var enableLeaderElection bool - var probeAddr string - var secureMetrics bool - var enableHTTP2 bool + var ( + enableLeaderElection bool + secureMetrics bool + enableHTTP2 bool + metricsAddr string + probeAddr string + tlsOpts []func(*tls.Config) + ) flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. " + "Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") @@ -255,7 +258,6 @@ func main() { c.NextProtos = []string{"http/1.1"} } - tlsOpts := []func(*tls.Config){} if !enableHTTP2 { tlsOpts = append(tlsOpts, disableHTTP2) }