app

package
v0.1.14 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: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Health

type Health struct {
	Name   string `json:"name,omitempty"`
	Status int    `json:"status,omitempty"` // status code indicating component health
}

Health represents the health status of a named service or component.

func GetHealth

func GetHealth() Health

GetHealth returns a Health snapshot reflecting the current PostgreSQL connectivity status. It is intended for API health-check endpoints only; CLI processes should not call this function because the required environment variables are unavailable in that context. The returned Status field is 2 when the database is reachable and 0 when it is not.

Example

ExampleGetHealth shows the typical usage in a /health HTTP endpoint handler. Requires env.InitEnv to be called at application startup. Status is 2 when the database is reachable, 0 otherwise.

package main

import (
	"fmt"

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

func main() {
	h := app.GetHealth()
	if h.Status == 2 {
		fmt.Printf("%s: healthy\n", h.Name)
	} else {
		fmt.Printf("%s: database unreachable\n", h.Name)
	}
}

type Version

type Version struct {
	Name        string `json:"name,omitempty"`        // Application name from the app.name environment key.
	Version     string `json:"version,omitempty"`     // Application version from the app.version environment key.
	Environment string `json:"environment,omitempty"` // Runtime environment (e.g. production, staging) from app.env.value.
	GoVersion   string `json:"goVersion,omitempty"`   // Go toolchain version used to build the binary.
	BuildInfo   string `json:"buildInfo,omitempty"`   // Module version from the embedded build info.
}

Version holds application version and build metadata typically returned by a version API endpoint.

func GetVersion

func GetVersion() Version

GetVersion returns a Version struct populated from the application environment configuration and the embedded Go build info. It is intended for use by API version endpoints; CLI processes may not have the required environment variables set.

Example

ExampleGetVersion shows how to expose build and runtime metadata via a /version HTTP endpoint. Requires env.InitEnv to be called at application startup.

package main

import (
	"fmt"

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

func main() {
	v := app.GetVersion()
	fmt.Printf("name=%s version=%s env=%s\n", v.Name, v.Version, v.Environment)
}

Jump to

Keyboard shortcuts

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