feat: initial Netts energy orchestrator

This commit is contained in:
你的用户名
2025-11-03 19:26:48 +08:00
commit 891c32e288
25 changed files with 2210 additions and 0 deletions

46
cmd/server/main.go Normal file
View File

@@ -0,0 +1,46 @@
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"
appconfig "github.com/D36u99er/bc-netts-energy/internal/config"
serverhttp "github.com/D36u99er/bc-netts-energy/internal/http"
applogger "github.com/D36u99er/bc-netts-energy/internal/logger"
"github.com/D36u99er/bc-netts-energy/internal/netts"
"github.com/D36u99er/bc-netts-energy/internal/service"
)
func main() {
configPath := flag.String("config", "", "path to configuration file")
flag.Parse()
cfg, err := appconfig.Load(*configPath)
if err != nil {
log.Fatalf("failed to load configuration: %v", err)
}
logger := applogger.New(cfg.Logging.Level, cfg.Logging.Format)
logger.Info("configuration loaded",
"address", cfg.Server.Address,
"netts_base_url", cfg.Netts.BaseURL,
)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
defer stop()
nettsClient := netts.New(cfg.Netts, logger, nil)
energySvc := service.NewEnergyService(cfg.Energy, nettsClient, logger)
httpServer := serverhttp.NewServer(cfg.Server, energySvc, logger)
if err := httpServer.Run(ctx); err != nil {
logger.Error("server terminated with error", "error", err)
os.Exit(1)
}
logger.Info("shutdown complete")
}