Files
es-demo/config/config.go

48 lines
1.3 KiB
Go

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