http

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module(
	"http",
	fx.Decorate(func(log *zap.Logger) *zap.Logger {
		return log.Named("http")
	}),
	fx.Provide(New),
	fx.Invoke(func(lc fx.Lifecycle, cfg Config, app *fiber.App, logger *zap.Logger) {
		lc.Append(fx.Hook{
			OnStart: func(_ context.Context) error {
				go func() {
					if err := app.Listen(cfg.Address); err != nil {
						logger.Error("server failed to start", zap.Error(err))
					}
				}()
				logger.Info("server starting", zap.String("address", cfg.Address))

				return nil
			},
			OnStop: func(ctx context.Context) error {
				logger.Warn("shutting down server")
				if err := app.ShutdownWithContext(ctx); err != nil {
					logger.Error("server shutdown failed", zap.Error(err))
					return fmt.Errorf("server shutdown failed: %w", err)
				}
				logger.Info("server shutdown completed")
				return nil
			},
		})
	}),
)

Functions

func New

func New(config Config, option Options, logger *zap.Logger) (*fiber.App, error)

func NewJSONErrorHandler

func NewJSONErrorHandler(logger *zap.Logger) fiber.ErrorHandler

func NewViewsErrorHandler

func NewViewsErrorHandler(logger *zap.Logger, template string, layouts ...string) fiber.ErrorHandler

Types

type Config

type Config struct {
	Address     string
	ProxyHeader string
	Proxies     []string
}

type Error

type Error struct {
	Message string `json:"message"`
	Code    int    `json:"code,omitempty"`
	Details any    `json:"details,omitempty"`
}

type ErrorResponse

type ErrorResponse struct {
	Error Error `json:"error"`
}

func NewErrorResponse

func NewErrorResponse(message string, code int, details any) ErrorResponse

type Options

type Options struct {
	// contains filtered or unexported fields
}

func (*Options) WithErrorHandler

func (o *Options) WithErrorHandler(handler fiber.ErrorHandler) *Options

func (*Options) WithGetOnly

func (o *Options) WithGetOnly() *Options

func (*Options) WithViews

func (o *Options) WithViews(views fiber.Views) *Options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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