You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/command/resource/client/grpc-config.go

44 lines
796 B

// 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
}