iop/packages/config/config.go
toki 2d6fde0876 기능: IOP 모노레포 스캐폴드 초기 구현
apps/node 중심 구현 — TCP+JSON transport, Hexagonal Architecture,
mock/cli adapter, fx DI, SQLite 실행 이력 저장.
edge/control-plane/worker는 cobra placeholder.
유닛 테스트 및 통합 테스트 클라이언트 계획서 추가.
2026-05-02 13:20:35 +09:00

100 lines
2.9 KiB
Go

package config
import (
"github.com/spf13/viper"
)
type NodeConfig struct {
Node NodeInfo `mapstructure:"node" yaml:"node"`
Transport TransportConf `mapstructure:"transport" yaml:"transport"`
TLS TLSConf `mapstructure:"tls" yaml:"tls"`
Runtime RuntimeConf `mapstructure:"runtime" yaml:"runtime"`
SQLite SQLiteConf `mapstructure:"sqlite" yaml:"sqlite"`
Logging LoggingConf `mapstructure:"logging" yaml:"logging"`
Metrics MetricsConf `mapstructure:"metrics" yaml:"metrics"`
Adapters AdaptersConf `mapstructure:"adapters" yaml:"adapters"`
}
type NodeInfo struct {
ID string `mapstructure:"id" yaml:"id"`
Name string `mapstructure:"name" yaml:"name"`
}
type TransportConf struct {
Listen string `mapstructure:"listen" yaml:"listen"`
}
type TLSConf struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled"`
Cert string `mapstructure:"cert" yaml:"cert"`
Key string `mapstructure:"key" yaml:"key"`
CA string `mapstructure:"ca" yaml:"ca"`
}
type RuntimeConf struct {
Concurrency int `mapstructure:"concurrency" yaml:"concurrency"`
WorkspaceRoot string `mapstructure:"workspace_root" yaml:"workspace_root"`
}
type SQLiteConf struct {
DSN string `mapstructure:"dsn" yaml:"dsn"`
}
type LoggingConf struct {
Level string `mapstructure:"level" yaml:"level"`
}
type MetricsConf struct {
Port int `mapstructure:"port" yaml:"port"`
}
type AdaptersConf struct {
Ollama OllamaConf `mapstructure:"ollama" yaml:"ollama"`
Vllm VllmConf `mapstructure:"vllm" yaml:"vllm"`
CLI CLIConf `mapstructure:"cli" yaml:"cli"`
}
type OllamaConf struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled"`
BaseURL string `mapstructure:"base_url" yaml:"base_url"`
}
type VllmConf struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled"`
Endpoint string `mapstructure:"endpoint" yaml:"endpoint"`
}
type CLIConf struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled"`
Profiles map[string]CLIProfileConf `mapstructure:"profiles" yaml:"profiles"`
}
type CLIProfileConf struct {
Command string `mapstructure:"command" yaml:"command"`
Args []string `mapstructure:"args" yaml:"args"`
Env []string `mapstructure:"env" yaml:"env"`
}
func Load(cfgFile string) (*NodeConfig, error) {
v := viper.New()
v.SetConfigFile(cfgFile)
setDefaults(v)
if err := v.ReadInConfig(); err != nil {
return nil, err
}
var cfg NodeConfig
if err := v.Unmarshal(&cfg); err != nil {
return nil, err
}
return &cfg, nil
}
func setDefaults(v *viper.Viper) {
v.SetDefault("transport.listen", "0.0.0.0:9090")
v.SetDefault("runtime.concurrency", 4)
v.SetDefault("runtime.workspace_root", "/tmp/iop/workspace")
v.SetDefault("sqlite.dsn", "file:iop.db?cache=shared&mode=rwc")
v.SetDefault("logging.level", "info")
v.SetDefault("metrics.port", 9091)
v.SetDefault("tls.enabled", false)
}