arquivei / go-app

A very opinionated app with life cycle and graceful shutdown.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-app

PkgGoDev Go Report Card License

A very opinionated app with life cycle and graceful shutdown.

Quickstart

Here is an example of a program that does nothing but it compiles and runs with all app features:

package main

import (
	"context"

	"github.com/arquivei/go-app"
)

var (
	version = "v0.0.0-dev"
	cfg     struct {
		app.Config
	}
)

func main() {
	defer app.Recover()
	app.Bootstrap(version, &cfg)
	app.RunAndWait(func(ctx context.Context) error {
		<-ctx.Done()
		return ctx.Err()
	})
}

Check all available options with go run ./ -h

Supported Fields:
FIELD                             FLAG                               ENV                               DEFAULT
-----                             -----                              -----                             -------
App.Log.Level                     -app-log-level                     APP_LOG_LEVEL                     info
App.Log.Human                     -app-log-human                     APP_LOG_HUMAN
App.AdminServer.Enabled           -app-adminserver-enabled           APP_ADMINSERVER_ENABLED           true
App.AdminServer.Addr              -app-adminserver-addr              APP_ADMINSERVER_ADDR              localhost:9000
App.AdminServer.With.DebugURLs    -app-adminserver-with-debugurls    APP_ADMINSERVER_WITH_DEBUGURLS    true
App.AdminServer.With.Metrics      -app-adminserver-with-metrics      APP_ADMINSERVER_WITH_METRICS      true
App.AdminServer.With.Probes       -app-adminserver-with-probes       APP_ADMINSERVER_WITH_PROBES       true
App.Shutdown.GracePeriod          -app-shutdown-graceperiod          APP_SHUTDOWN_GRACEPERIOD          3s
App.Shutdown.Timeout              -app-shutdown-timeout              APP_SHUTDOWN_TIMEOUT              5s

There is a special option to print out the default configuration in env or yaml format: go run . -app-config-output=env.

APP_LOG_LEVEL=info
APP_LOG_HUMAN=
APP_ADMINSERVER_ENABLED=true
APP_ADMINSERVER_ADDR=localhost:9000
APP_ADMINSERVER_WITH_DEBUGURLS=true
APP_ADMINSERVER_WITH_METRICS=true
APP_ADMINSERVER_WITH_PROBES=true
APP_SHUTDOWN_GRACEPERIOD=3s
APP_SHUTDOWN_TIMEOUT=5s
APP_CONFIG_OUTPUT=

Version can be overwritten in compile time using -ldflags:

-ldflags="-X main.version=v0.0.1"

More information on the presentation slides.

Use the present tool to render the slides or you can check it online at https://go-talks.appspot.com/github.com/arquivei/go-app/docs/presentation.slide

Minimal dependencies

  • prometheus/client_golang: Metrics
  • rs/zerolog: Structured log in JSON format
  • stretchr/testify: Better unit testing asserts

Getting Started

These instructions will give you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on deploying the project on a live system.

Prerequisites

Requirements for the software and other tools to build, test and push:

Linting

Please run golangci-lint run before submitting code.

Godoc

To read the godoc documentation run:

godoc -http=localhost:6060

and open http://localhost:6060 on your browser.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use Semantic Versioning for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the BSD 3-Clause - see the LICENSE.txt file for details.

About

A very opinionated app with life cycle and graceful shutdown.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Go 100.0%