idecnode/cmd/api/api.go

50 lines
989 B
Go
Raw Normal View History

2024-10-20 03:39:07 +03:00
package api
import (
2024-10-29 01:21:05 +03:00
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
2024-10-20 03:39:07 +03:00
"github.com/urfave/cli/v2"
2024-10-29 01:21:05 +03:00
"gitrepo.ru/neonxp/idecnode/pkg/apiv1"
"gitrepo.ru/neonxp/idecnode/pkg/apiv2"
2024-10-20 03:39:07 +03:00
"gitrepo.ru/neonxp/idecnode/pkg/config"
"gitrepo.ru/neonxp/idecnode/pkg/idec"
)
var APICommand *cli.Command = &cli.Command{
Name: "api",
Description: "Start api server",
Action: func(c *cli.Context) error {
configPath := c.String("config")
cfg, err := config.New(configPath)
if err != nil {
return err
}
idecApi, err := idec.New(cfg)
if err != nil {
return err
}
defer idecApi.Close()
2024-10-29 01:21:05 +03:00
e := echo.New()
2024-10-20 03:39:07 +03:00
2024-10-29 01:21:05 +03:00
e.Use(
middleware.Recover(),
middleware.Logger(),
)
apiv1.New(idecApi, cfg).Register(e)
apiv2.New(idecApi, cfg).Register(e)
e.Static("/", "./web/dist")
return e.Start(cfg.Listen)
2024-10-20 03:39:07 +03:00
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
DefaultText: "config path",
Value: "./etc/node.yaml",
},
},
}