loader

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFromEnv added in v0.1.9

func LoadFromEnv() httpserver.Runner

LoadFromEnv creates an HTTP Runner from the koanf env singleton. It reads app.runmode and http.server.port, then returns the appropriate Runner. The caller is responsible for starting the server (call Start in a goroutine) and stopping it (call Shutdown on signal).

Typical usage in the composition root:

runner := loader.LoadFromEnv()
go func() {
    if err := runner.Start(ginRouter); err != nil {
        slog.Error("Http server stopped with error", "error", err)
    }
}()
shutdown.Wait()
runner.Shutdown(ctx)
Example

ExampleLoadFromEnv shows how LoadFromEnv is used in the composition root. It reads app.runmode and http.server.port from the koanf env singleton and returns the appropriate Runner. The caller owns the goroutine and shutdown:

runner := loader.LoadFromEnv()
go func() {
    if err := runner.Start(ginRouter); err != nil {
        slog.Error("Http server stopped with error", "error", err)
    }
}()
shutdown.Wait()
runner.Shutdown(ctx)
package main

import (
	"fmt"

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

func main() {
	runner := loader.LoadFromEnv()
	fmt.Println(runner != 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