Implement web API foundation
Add application container, Gin router, graceful shutdown handler, and version endpoint. This establishes the skeleton for the WebDisk HTTP API as described in the architecture. - Add internal/app/WebApp for runtime dependencies and version - Add internal/server/router with GET /api/v1/version route - Add graceful shutdown runner with signal handling in cmd/serve - Add internal/api/ErrorResponse for standard HTTP error body - Update roadmap, architecture, and decisions documentation
This commit is contained in:
43
cmd/serve.go
Normal file
43
cmd/serve.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/dhao2001/mygo/internal/app"
|
||||
"github.com/dhao2001/mygo/internal/config"
|
||||
"github.com/dhao2001/mygo/internal/server"
|
||||
)
|
||||
|
||||
var serveConfigFile string
|
||||
|
||||
var serveCmd = &cobra.Command{
|
||||
Use: "serve",
|
||||
Short: "Start the MyGO HTTP server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
v := config.New()
|
||||
cfg, err := config.Load(v, serveConfigFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load config: %w", err)
|
||||
}
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
webApp := app.NewWebApp(cfg)
|
||||
router := server.NewRouter(webApp)
|
||||
addr := server.Address(webApp.Config.Server)
|
||||
|
||||
return server.RunWithGracefulShutdown(ctx, addr, router)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
serveCmd.Flags().StringVar(&serveConfigFile, "config", "", "config file path")
|
||||
rootCmd.AddCommand(serveCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user