inou/lib/config.go

77 lines
1.7 KiB
Go

package lib
import (
"log"
"os"
"strings"
)
// Production paths - single source of truth
const (
DBPathDefault = "/tank/inou/data/inou.db"
KeyPathDefault = "/tank/inou/master.key"
configFile = "/tank/inou/anthropic.env"
)
// Init initializes all lib subsystems (crypto, database) with production defaults
func Init() error {
if err := CryptoInit(KeyPathDefault); err != nil {
return err
}
return DBInit(DBPathDefault)
}
var (
GeminiKey string = ""
AnthropicKey string = ""
SystemAccessorID string = "7b3a3ee1c2776dcd" // Default fallback
)
func ConfigInit() {
data, err := os.ReadFile(configFile)
if err != nil {
log.Printf("Warning: %s not found: %v", configFile, err)
} else {
for _, line := range strings.Split(string(data), "\n") {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "#") {
continue
}
parts := strings.SplitN(line, "=", 2)
if len(parts) != 2 {
continue
}
key := strings.TrimSpace(parts[0])
value := strings.TrimSpace(parts[1])
switch key {
case "GEMINI_API_KEY":
GeminiKey = value
case "ANTHROPIC_API_KEY":
AnthropicKey = value
case "SYSTEM_ACCESSOR_ID":
SystemAccessorID = value
}
}
}
// Fallback to environment variables if not set from file
if GeminiKey == "" {
GeminiKey = os.Getenv("GEMINI_API_KEY")
}
if AnthropicKey == "" {
AnthropicKey = os.Getenv("ANTHROPIC_API_KEY")
}
if SystemAccessorID == "" {
if envID := os.Getenv("SYSTEM_ACCESSOR_ID"); envID != "" {
SystemAccessorID = envID
}
}
// Initialize SystemContext with loaded ID
SystemContext = &AccessContext{
IsSystem: true,
AccessorID: SystemAccessorID,
}
}