A simple app framework for bootstrapping logging, otel, and servers from config and environment
Go to file
2025-01-04 12:25:16 -05:00
pkg Go app framework 2025-01-04 12:24:42 -05:00
.gitignore Initial commit 2025-01-04 17:13:39 +00:00
go.mod Go app framework 2025-01-04 12:24:42 -05:00
go.sum Go app framework 2025-01-04 12:24:42 -05:00
LICENSE Initial commit 2025-01-04 17:13:39 +00:00
README.md Go app framework 2025-01-04 12:24:42 -05:00
TODO.md Add TODO 2025-01-04 12:25:16 -05:00

go-app

A simple app framework for bootstrapping logging, otel, and servers from config and environment

Usage

  • Use the helper function to load config file (if given with -config) and apply configuration through environment. This will prepare your app config and logging.

  • Load up HTTP routes and health checks.

  • Start the app.

  • Wait for it to be done and do any extra cleanup.

Here is a reference main.go

package main

import (
	"context"
	"os"
	"os/signal"

	"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
	"golang.org/x/sys/unix"
)

func main() {
	ctx, cncl := signal.NotifyContext(context.Background(), os.Kill, unix.SIGTERM)
	defer cncl()

	ctx = app.MustSetupConfigAndLogging(ctx)

	awApp := app.App{
		AppContext: ctx,
		HTTP: &app.AppHTTP{
            // Load up your HTTP methods here
			Funcs: []srv.HTTPFunc{
				{
					Path: "/test",
					HandlerFunc: func(w http.ResponseWriter, r *http.Request) {
						w.WriteHeader(http.StatusNotImplemented)
						w.Write([]byte("unimplemented test method"))
					},
				},
			},
            // Load up health checks here
			HealthChecks: []srv.HealthCheckFunc{
				func(ctx context.Context) error {
					return errors.New("health check unimplemented")
				},
			},
		},
	}

	awApp.MustRun()
	<-awApp.Done()
}