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).
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.
Click to show internal directories.
Click to hide internal directories.