MCPcopy Index your code
hub / github.com/InferCore/InferCore / serveCmd

Function serveCmd

cmd/infercore/main.go:63–101  ·  view source on GitHub ↗
(cfgPath *string)

Source from the content-addressed store, hash-verified

61}
62
63func serveCmd(cfgPath *string) *cobra.Command {
64 return &cobra.Command{
65 Use: "serve",
66 Short: "Run the HTTP gateway",
67 RunE: func(cmd *cobra.Command, args []string) error {
68 cfg, err := config.Load(*cfgPath)
69 if err != nil {
70 return err
71 }
72 srv := server.New(cfg)
73 defer func() {
74 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
75 defer cancel()
76 _ = srv.Shutdown(ctx)
77 }()
78
79 addr := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
80 readTO, writeTO, idleTO := server.HTTPLayerTimeouts(cfg)
81 httpServer := &http.Server{
82 Addr: addr,
83 Handler: srv.Routes(),
84 ReadHeaderTimeout: 5 * time.Second,
85 ReadTimeout: readTO,
86 WriteTimeout: writeTO,
87 IdleTimeout: idleTO,
88 }
89 go func() {
90 log.Printf("infercore listening on %s", addr)
91 if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
92 log.Fatalf("server failed: %v", err)
93 }
94 }()
95 sig := make(chan os.Signal, 1)
96 signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
97 <-sig
98 return httpServer.Shutdown(context.Background())
99 },
100 }
101}
102
103func traceCmd(cfgPath *string) *cobra.Command {
104 return &cobra.Command{

Callers 1

rootCmdFunction · 0.85

Calls 6

ShutdownMethod · 0.95
LoadFunction · 0.92
NewFunction · 0.92
HTTPLayerTimeoutsFunction · 0.92
RoutesMethod · 0.80
ShutdownMethod · 0.65

Tested by

no test coverage detected