mirror of
https://github.com/status-im/consul.git
synced 2025-01-16 08:45:37 +00:00
9dc24448ae
* grpc client default in plaintext mode * renaming and fix linter * update the description and remove the context * trim tests
44 lines
796 B
Go
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
|
|
}
|