iop/apps/node/cmd/iop-node/main.go
toki 173d2586e8 리팩터: node 서버 코드 제거 및 클라이언트 구조로 전환
- transport/{server,session,frame,codec,tls}.go 삭제
- packages/protocol/protocol.go 삭제 (JSON 기반 메시지 타입)
- bootstrap/module.go에서 transport.Server 와이어링 제거
- TransportConf.Listen → EdgeAddr (node는 서버가 아닌 클라이언트)
- configs/node.yaml transport.listen → transport.edge_addr

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 17:54:58 +09:00

85 lines
1.7 KiB
Go

package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"go.uber.org/fx"
"gopkg.in/yaml.v3"
"iop/apps/node/internal/bootstrap"
"iop/packages/config"
"iop/packages/version"
)
var cfgFile string
func main() {
if err := rootCmd().Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func rootCmd() *cobra.Command {
root := &cobra.Command{
Use: "iop-node",
Short: "IOP Node Agent — runs inference adapters on this device",
}
root.PersistentFlags().StringVarP(&cfgFile, "config", "c", "configs/node.yaml", "config file path")
root.AddCommand(serveCmd(), versionCmd(), configCmd())
return root
}
func serveCmd() *cobra.Command {
return &cobra.Command{
Use: "serve",
Short: "Start the IOP node (connects to edge)",
RunE: func(cmd *cobra.Command, _ []string) error {
cfg, err := config.Load(cfgFile)
if err != nil {
return fmt.Errorf("load config: %w", err)
}
app := fx.New(bootstrap.Module(cfg))
app.Run()
return nil
},
}
}
func versionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print IOP node version",
Run: func(_ *cobra.Command, _ []string) {
fmt.Println(version.Version)
},
}
}
func configCmd() *cobra.Command {
cfgGroup := &cobra.Command{
Use: "config",
Short: "Config management commands",
}
printCmd := &cobra.Command{
Use: "print",
Short: "Print the resolved configuration",
RunE: func(_ *cobra.Command, _ []string) error {
cfg, err := config.Load(cfgFile)
if err != nil {
return fmt.Errorf("load config: %w", err)
}
enc := yaml.NewEncoder(os.Stdout)
enc.SetIndent(2)
return enc.Encode(cfg)
},
}
cfgGroup.AddCommand(printCmd)
return cfgGroup
}