app

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

README

app

Import path: github.com/InsideGallery/core/app

Overview

app provides process entrypoint helpers for InsideGallery HTTP services and NATS workers. The helpers install logging and metrics bundle imports, start the profiler monitor, wire service-specific initialization callbacks, register shutdown handlers, and then run the server or worker loop.

Main APIs

  • InitRouter is the HTTP setup callback: func(context.Context, *fiber.App) error.
  • WebMain(name string, cfg *webserver.Config, initRouter InitRouter) starts a Fiber HTTP service.
  • InitSubscriptions is the NATS setup callback: func(context.Context, *subscriber.Subscriber) error.
  • NATSMain(name, monitorAddr string, initSubs InitSubscriptions) starts a NATS subscriber worker.

Usage

cfg, err := webserver.GetEnvConfig()
if err != nil {
	return err
}

app.WebMain("api", cfg, func(ctx context.Context, router *fiber.App) error {
	router.Get("/ping", func(c fiber.Ctx) error {
		return c.SendString("ok")
	})

	return nil
})

Configuration And Operations

WebMain reads logging and metrics configuration through fastlog.GetConfigFromEnv and metrics.GetEnvConfig, starts profiler.Monitor(cfg.MonitorAddr), installs the metrics middleware, and listens on cfg.Address. The caller usually builds cfg with server/webserver.GetEnvConfig.

NATSMain reads logging and metrics configuration the same way, creates the default NATS client through mq-balancer, registers a NATS health check, and waits on the subscriber. Its source documents the expected NATS environment variables as NATS_ADDR, NATS_CONCURRENT_SIZE, and NATS_READ_TIMEOUT.

Both entrypoints register SIGINT, SIGTERM, and SIGQUIT callbacks through oslistener. Fatal logging, metrics, initialization, listen, or worker errors call os.Exit(1), so use lower-level packages directly when a caller must handle startup errors itself.

Documentation

Overview

Package app provides reusable application entrypoints for HTTP and NATS services. Modeled after github.com/InsideGallery/core/app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NATSMain

func NATSMain(name, monitorAddr string, initSubs InitSubscriptions)

NATSMain is the complete entrypoint for a NATS worker service. It handles: logging → profiler → NATS connect → init closure → signals → wait. Reads NATS_ADDR, NATS_CONCURRENT_SIZE, NATS_READ_TIMEOUT from environment.

func WebMain

func WebMain(name string, cfg *httpserver.Config, initRouter InitRouter)

WebMain is the complete entrypoint for an HTTP service. It handles: logging → profiler → init closure → signals → listen. The caller provides only the service-specific wiring in initRouter.

Types

type InitRouter

type InitRouter func(ctx context.Context, app *fiber.App) error

InitRouter is a closure that wires service-specific dependencies (DB, auth, etc.) and registers routes on the Fiber app. If it returns nil, all setup succeeded.

type InitSubscriptions

type InitSubscriptions func(ctx context.Context, sub *subscriber.Subscriber) error

InitSubscriptions is a closure that wires service-specific dependencies (DB, etc.) and registers NATS subscriptions. If it returns nil, all setup succeeded.

Jump to

Keyboard shortcuts

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