Go app framework
This commit is contained in:
60
README.md
60
README.md
@ -1,3 +1,61 @@
|
||||
# go-app
|
||||
|
||||
A simple app framework for bootstrapping logging, otel, and servers from config and environment
|
||||
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()
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user