consul/command/resource/client/grpc-config.go
wangxinyi7 9dc24448ae
grpc client default in plaintext mode (#19412)
* grpc client default in plaintext mode

* renaming and fix linter

* update the description and remove the context

* trim tests
2023-11-28 10:58:57 -08:00

44 lines
796 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package client
import (
"os"
)
const (
// GRPCAddrEnvName defines an environment variable name which sets the gRPC
// server address for the consul CLI.
GRPCAddrEnvName = "CONSUL_GRPC_ADDR"
)
type GRPCConfig struct {
Address string
}
func GetDefaultGRPCConfig() *GRPCConfig {
return &GRPCConfig{
Address: "localhost:8502",
}
}
func LoadGRPCConfig(defaultConfig *GRPCConfig) *GRPCConfig {
if defaultConfig == nil {
defaultConfig = GetDefaultGRPCConfig()
}
overwrittenConfig := loadEnvToDefaultConfig(defaultConfig)
return overwrittenConfig
}
func loadEnvToDefaultConfig(config *GRPCConfig) *GRPCConfig {
if addr := os.Getenv(GRPCAddrEnvName); addr != "" {
config.Address = addr
}
return config
}