api

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module(
	"api",
	fx.Decorate(func(log *zap.Logger) *zap.Logger {
		return log.Named("api")
	}),
	fx.Provide(http.NewJSONErrorHandler),
	fx.Provide(func(log *zap.Logger) http.Options {
		return *(&http.Options{}).WithErrorHandler(http.NewJSONErrorHandler(log))
	}),
	fx.Provide(NewLinks),
	fx.Invoke(func(app *fiber.App, l *Links, config Config) {
		api := app.Group("/api/v1")

		apidoc.SwaggerInfo.Version = version.AppVersion
		api.Get("/docs/*", swagger.New(swagger.Config{
			Layout: "BaseLayout",
		}))

		if config.CORSAllowOrigins != "" {
			api.Use(cors.New(cors.Config{
				AllowOrigins:     config.CORSAllowOrigins,
				AllowCredentials: true,
				MaxAge:           86400,
			}))
		}

		api.Use(jsonify.New())

		l.Register(api.Group("/links"))

		api.Use(func(ctx *fiber.Ctx) error {
			return ctx.SendStatus(fiber.StatusNotFound)
		})
	}),
)

Functions

This section is empty.

Types

type Config

type Config struct {
	CORSAllowOrigins string
}
type Links struct {
	handler.Base
	// contains filtered or unexported fields
}
func NewLinks(links *links.Service, stats *stats.Service, v *validator.Validate, l *zap.Logger) *Links

func (*Links) Register

func (c *Links) Register(router fiber.Router)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳