appx

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 8 Imported by: 1

README

appx

build-img pkg-img version-img

Go library for building applications. Dramatically simple. For a CLI tool see cristalhq/acmd.

Features

  • Simple API.
  • Dependency-free.
  • Dramatically simple.

See these docs or GUIDE.md for more details.

Install

Go version 1.18+

go get github.com/cristalhq/appx

Example

import (
	"context"
	"os"

	"github.com/cristalhq/appx"
)

func main() {
	ctx := appx.Context()

	if err := run(ctx, os.Args[1:]); err != nil {
		panic(err)
	}
}

func run(ctx context.Context, args []string) error {
	// do good things
	return nil
}

See examples: example_test.go.

License

MIT License.

Documentation

Index

Constants

View Source
const IsDebugBuild = false

IsDebugBuild reports whether compilation was with `-tags=debug` flag.

Variables

This section is empty.

Functions

func BuildInfo added in v0.5.0

func BuildInfo() (revision string, at time.Time, isModified, ok bool)

BuildInfo of the app (if -buildvcs flag provided).

func Context

func Context() context.Context

Context of the application listening SIGINT and SIGTERM signals.

func Env added in v0.4.0

func Env() string

Env where application is running. Can be set via SetEnv func.

func OnSignal added in v0.5.0

func OnSignal(ctx context.Context, sig os.Signal, fn func(ctx context.Context))

OnSignal run fn. Function is async, context is used to close underlying goroutine.

func SelfSignal added in v0.5.0

func SelfSignal(sig os.Signal) error

SelfSignal sends signal to the current process.

func SetEnv added in v0.4.0

func SetEnv(env, def string) string

SetEnv for the application from environment variable or a default. Can be called once, all next calls panics. Example:

appx.SetEnv("ENV", "dev") // set from ENV or set default "dev"
appx.SetEnv("ENV", "") // set from ENV or leave unset
appx.SetEnv("", "dev") // set "dev" directly

This function should be called at the start of the application.

func Uptime added in v0.2.0

func Uptime() time.Duration

Uptime of the application.

Types

This section is empty.

Jump to

Keyboard shortcuts

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