mirror of https://github.com/milvus-io/milvus.git
feature: add a prefix on environment config (#40623)
fix #40622 Signed-off-by: xiaofanluan <xiaofan.luan@zilliz.com>pull/40643/head
parent
f6fb4bc442
commit
7210fc9780
|
@ -24,15 +24,20 @@ import (
|
|||
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
|
||||
)
|
||||
|
||||
// DefaultEnvPrefix is the default prefix for environment variables
|
||||
const DefaultEnvPrefix = "MILVUS_CONF_"
|
||||
|
||||
type EnvSource struct {
|
||||
configs *typeutil.ConcurrentMap[string, string]
|
||||
KeyFormatter func(string) string
|
||||
prefix string
|
||||
}
|
||||
|
||||
func NewEnvSource(KeyFormatter func(string) string) EnvSource {
|
||||
es := EnvSource{
|
||||
configs: typeutil.NewConcurrentMap[string, string](),
|
||||
KeyFormatter: KeyFormatter,
|
||||
prefix: DefaultEnvPrefix,
|
||||
}
|
||||
|
||||
for _, value := range os.Environ() {
|
||||
|
@ -43,6 +48,15 @@ func NewEnvSource(KeyFormatter func(string) string) EnvSource {
|
|||
envKey := KeyFormatter(key)
|
||||
es.configs.Insert(key, value)
|
||||
es.configs.Insert(envKey, value)
|
||||
|
||||
// Handle prefixed environment variables
|
||||
// e.g., MILVUS_MINIO_PORT will override MINIO_PORT
|
||||
if strings.HasPrefix(key, es.prefix) {
|
||||
originalKey := key[len(es.prefix):]
|
||||
originalEnvKey := KeyFormatter(originalKey)
|
||||
es.configs.Insert(originalKey, value)
|
||||
es.configs.Insert(originalEnvKey, value)
|
||||
}
|
||||
}
|
||||
return es
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue