component

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package component provides HTTP server lifecycle integration for bootstrap.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Component

func Component(handler func() http.Handler) bootstrap.IComponent

Component wraps the HTTP server as a bootstrap.IComponent.

handler is a lazy provider called during Init() to obtain the http.Handler (typically *gin.Engine). Passing a function rather than the handler directly defers evaluation until Init() time, at which point the Gin component has already been initialised.

Typical usage with a bridge variable in main:

var router *gin.Engine
Add(gin.Component(origins, func(r *gin.Engine) {
    router = r
    adapter.Mount(r)
})).
Add(component.Component(func() http.Handler { return router }))
Example

ExampleComponent shows how Component() is used in a bootstrap registration chain. It reads app.runmode and http.server.port from env during Init().

Init() starts the HTTP server in a background goroutine and returns immediately. Startup errors (e.g. port already in use) are handled asynchronously via shutdown.Trigger(). Close() gracefully drains in-flight requests.

Typical usage with a bridge variable in main:

var router *gin.Engine
Add(ginComp.Component(func(r *gin.Engine) {
    router = r
    adapter.Mount(r)
})).
Add(httpComp.Component(func() http.Handler { return router }))
package main

import (
	"fmt"
	"net/http"

	httpComp "github.com/phcp-tech/common-library-golang/httpserver/component"
)

func main() {
	c := httpComp.Component(func() http.Handler { return http.NewServeMux() })
	fmt.Println(c != nil)
}
Output:
true

Types

This section is empty.

Jump to

Keyboard shortcuts

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