componentwithlambda

package
v0.1.26 Latest Latest
Warning

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

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

Documentation

Overview

Package componentwithlambda provides HTTP server lifecycle integration for bootstrap, with AWS Lambda support.

Use this package instead of httpserver/component when the service may be deployed on AWS Lambda. It reads app.runmode from env during Init() and selects the appropriate runner:

  • "aws_lambda" → httpserver/lambda.NewHttpServer()
  • anything else → httpserver.NewHttpServer() (plain HTTP/HTTPS)

Importing this package pulls in the AWS Lambda SDK. Services that never run on Lambda should use httpserver/component to keep their binary free of unnecessary dependencies.

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 with Lambda support.

handler is a lazy provider called during Init() to obtain the http.Handler (typically *gin.Engine). The runner is selected at Init() time based on the app.runmode env key.

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 }))
Example

ExampleComponent shows how Component() is used in a bootstrap registration chain.

The runner is selected at Init() time based on the app.runmode env key:

  • "aws_lambda" → AWS Lambda runner (httpserver/lambda)
  • anything else → plain HTTP server (httpserver)

Import this package instead of httpserver/component when the service may be deployed on AWS Lambda. It pulls in the AWS Lambda SDK, so services that never run on Lambda should use httpserver/component to avoid the extra dependency.

var router *gin.Engine
bootstrap.New().
    Add(envComp.Component("config/app.toml", &configFS)). // 1st — env
    Add(logComp.Component()).                              // 2nd — log
    Add(ginComp.Component(func(r *gin.Engine) {
        router = r
        adapter.Mount(r)
    })).
    Add(httpComp.Component(func() http.Handler { return router })).
    Run()
package main

import (
	"fmt"
	"net/http"

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

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