summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
authorexatombe <jeremy27.clara22@gmail.com>2025-11-02 23:12:12 +0100
committerexatombe <jeremy27.clara22@gmail.com>2025-11-02 23:12:12 +0100
commit549a8b6b8c97c357495c9df198c21e940f56b6a5 (patch)
tree373c2dee7182dacf69179a85e7863bd4f913a991 /internal/config/config.go
parent8a5090a0ada81d8a46c6fad1f36316b6415ff651 (diff)
feat: remove proto files and related gRPC code
- Deleted the generated proto file `sovrabase.proto` and its corresponding Go files `sovrabase.pb.go` and `sovrabase_grpc.pb.go`. - Removed the test script `test_orchestrator_api.go` and added a new configuration file `config.yaml` for orchestrator settings. - Introduced CORS middleware in `internal/middleware/cors.go` with comprehensive tests in `internal/middleware/cors_test.go`. - Updated orchestrator tests in `internal/orchestrator/test_orchestrator_api.go` to ensure proper database lifecycle management.
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go42
1 files changed, 25 insertions, 17 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index ba616f9..4965a36 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -2,8 +2,9 @@ package config
import (
"fmt"
+ "os"
- "github.com/BurntSushi/toml"
+ "gopkg.in/yaml.v3"
// Import des packages Docker et Kubernetes pour la gestion des conteneurs
_ "github.com/docker/docker/client"
@@ -15,36 +16,37 @@ import (
// RPC holds RPC configuration
type RPC struct {
- RPCSecret string `toml:"rpc_secret"`
- RPCAddr string `toml:"rpc_addr"`
+ RPCSecret string `yaml:"rpc_secret"`
+ RPCAddr string `yaml:"rpc_addr"`
}
// API holds API configuration
type API struct {
- APIAddr string `toml:"api_addr"`
- APIDomain string `toml:"api_domain"`
+ APIAddr string `yaml:"api_addr"`
+ CORSAllow []string `yaml:"cors_allow"`
+ Domain string `yaml:"domain"`
}
// InternalDB holds internal database configuration
type InternalDB struct {
- Manager string `toml:"manager"`
- URI string `toml:"uri"`
+ Manager string `yaml:"manager"`
+ URI string `yaml:"uri"`
}
// Orchestrator holds container orchestration configuration
type Orchestrator struct {
- Type string `toml:"type"` // "docker" or "kubernetes"
- DockerHost string `toml:"docker_host"` // Docker/Podman socket or remote host
- KubeAPI string `toml:"kube_api"` // Kubernetes API endpoint
- KubeToken string `toml:"kube_token"` // Kubernetes API token
- Namespace string `toml:"namespace"` // Kubernetes namespace for database deployments
+ Type string `yaml:"type"` // "docker" or "kubernetes"
+ DockerHost string `yaml:"docker_host"` // Docker/Podman socket or remote host
+ KubeAPI string `yaml:"kube_api"` // Kubernetes API endpoint
+ KubeToken string `yaml:"kube_token"` // Kubernetes API token
+ Namespace string `yaml:"namespace"` // Kubernetes namespace for database deployments
}
// Cluster holds cluster/distributed configuration
type Cluster struct {
- NodeID string `toml:"node_id"`
- IsRPCServer bool `toml:"is_rpc_server"`
- RPCServers []string `toml:"rpc_servers"`
+ NodeID string `yaml:"node_id"`
+ IsRPCServer bool `yaml:"is_rpc_server"`
+ RPCServers []string `yaml:"rpc_servers"`
}
// Config holds the application configuration
@@ -57,10 +59,16 @@ type Config struct {
Cluster Cluster
}
-// LoadConfig loads configuration from a TOML file
+// LoadConfig loads configuration from a YAML file
func LoadConfig(filePath string) (*Config, error) {
var config Config
- if _, err := toml.DecodeFile(filePath, &config); err != nil {
+
+ data, err := os.ReadFile(filePath)
+ if err != nil {
+ return nil, fmt.Errorf("failed to read config file: %w", err)
+ }
+
+ if err := yaml.Unmarshal(data, &config); err != nil {
return nil, fmt.Errorf("failed to decode config file: %w", err)
}