feat: opensearch客户端初始化 feat: 索引模板接口 ai: 开发准则 chore: TDD流水线脚本
This commit is contained in:
47
config/config.go
Normal file
47
config/config.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Package config provides global configuration management for the application.
|
||||
// This is a simplified implementation suitable for the experimental phase.
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
var (
|
||||
// Endpoint is the OpenSearch cluster endpoint URL.
|
||||
Endpoint string
|
||||
|
||||
// Region is the AWS region where the OpenSearch cluster is located.
|
||||
Region string
|
||||
|
||||
// AccessKey is the AWS access key ID for authentication.
|
||||
AccessKey string
|
||||
|
||||
// SecretKey is the AWS secret access key for authentication.
|
||||
SecretKey string
|
||||
)
|
||||
|
||||
// Load loads configuration from a .env file and then from environment variables.
|
||||
// If the file does not exist, it only loads from environment variables without error.
|
||||
func Load(filePath string) error {
|
||||
// Load .env file if it exists
|
||||
// This will set environment variables from the file
|
||||
_ = godotenv.Load(filePath)
|
||||
|
||||
// Initialize global config from environment variables
|
||||
Endpoint = os.Getenv("ES_ENDPOINT")
|
||||
AccessKey = os.Getenv("AWS_ACCESS_KEY_ID")
|
||||
SecretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
|
||||
Region = os.Getenv("AWS_REGION")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Init initializes the global configuration from environment variables.
|
||||
func Init() {
|
||||
Endpoint = os.Getenv("ES_ENDPOINT")
|
||||
AccessKey = os.Getenv("AWS_ACCESS_KEY_ID")
|
||||
SecretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
|
||||
Region = os.Getenv("AWS_REGION")
|
||||
}
|
||||
Reference in New Issue
Block a user