summaryrefslogtreecommitdiff
path: root/internal/config/config.go
blob: c87220387f84d9c650b243a4d4c5c2b27d4f61aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package config

import (
	"fmt"

	"github.com/BurntSushi/toml"
)

// RPC holds RPC configuration
type RPC struct {
	RPCSecret string
	RPCAddr   string
}

// API holds API configuration
type API struct {
	APIAddr   string
	APIDomain string
}

// InternalDB holds internal database configuration
type InternalDB struct {
	Manager string
	URI     string
}

// ExternalDB holds external database configuration
type ExternalDB struct {
	Manager string
	URI     string
}

// Cluster holds cluster/distributed configuration
type Cluster struct {
	NodeID      string
	IsRPCServer bool
	RPCServers  []string
}

// Config holds the application configuration
type Config struct {
	Region     string
	RPC        RPC
	API        API
	InternalDB InternalDB
	ExternalDB ExternalDB
	Cluster    Cluster
}

// LoadConfig loads configuration from a TOML file
func LoadConfig(filePath string) (*Config, error) {
	var config Config
	if _, err := toml.DecodeFile(filePath, &config); err != nil {
		return nil, fmt.Errorf("failed to decode config file: %w", err)
	}

	// Set defaults
	if config.Region == "" {
		config.Region = "supabase"
	}

	return &config, nil
}