rest

package
v0.0.0-...-8d6c78c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RestCmd = &cobra.Command{
	Use:   "rest",
	Short: "rest api",
	Run: func(cmd *cobra.Command, args []string) {

		dep := common.GetCommonDependency()
		defer dep.Logger.Sync()

		app := fiber.New()

		app.Use(recover.New(recover.Config{
			Next:             nil,
			EnableStackTrace: true,
		}))

		Router(dep, app)

		addr := fmt.Sprintf(":%d", dep.Config.App.Port)

		fmt.Printf("Server is listening on port %d\n", dep.Config.App.Port)

		go func() {
			if err := app.Listen(addr); err != nil && err != http.ErrServerClosed {
				dep.Logger.Fatal("shutting down the server")
			}
		}()

		quit := make(chan os.Signal, 1)

		signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
		<-quit
		dep.Logger.Info("Shutting down server...")

		ctx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)
		defer shutdownCancel()
		if err := app.ShutdownWithContext(ctx); err != nil {
			dep.Logger.Fatal("Server forced to shutdown: ", zap.Any("err", err.Error()))
		}

		dep.Logger.Info("Server exiting")
	},
}

RestCmd represents the rest command.

Functions

func Router

func Router(dep *common.RestDependency, app *fiber.App)

func RouterSeven

func RouterSeven(dep *common.RestDependency, router fiber.Router)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL