2025-01-04 17:13:39 +00:00
|
|
|
# go-app
|
|
|
|
|
2025-01-04 17:24:42 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
```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()
|
|
|
|
}
|
|
|
|
```
|