初版提交
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"complie-erlang/config"
|
||||
"gopkg.in/yaml.v2"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type ConfigGenerator struct {
|
||||
config *config.GeneratorConfig
|
||||
}
|
||||
|
||||
func NewConfigGenerator(cfg *config.GeneratorConfig) *ConfigGenerator {
|
||||
return &ConfigGenerator{config: cfg}
|
||||
}
|
||||
|
||||
func (g *ConfigGenerator) Generate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Run1() {
|
||||
// 加载配置
|
||||
cfg := loadConfig()
|
||||
|
||||
generator := NewConfigGenerator(cfg)
|
||||
if err := generator.Generate(); err != nil {
|
||||
log.Fatalf("Error generating config: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func loadConfig() *config.GeneratorConfig {
|
||||
configFile := "config.yaml"
|
||||
if len(os.Args) > 1 {
|
||||
configFile = os.Args[1]
|
||||
}
|
||||
|
||||
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||
log.Printf("Config file not found, using default config")
|
||||
return config.DefaultConfig()
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
log.Printf("Failed to read config file, using default: %v", err)
|
||||
return config.DefaultConfig()
|
||||
}
|
||||
|
||||
var cfg config.GeneratorConfig
|
||||
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||
log.Printf("Failed to parse config file, using default: %v", err)
|
||||
return config.DefaultConfig()
|
||||
}
|
||||
|
||||
return &cfg
|
||||
}
|
||||
Reference in New Issue
Block a user