reference implementation of go app
This commit is contained in:
27
main.go
27
main.go
@ -13,7 +13,6 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
@ -24,6 +23,7 @@ import (
|
||||
optshttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/config"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/demohttp"
|
||||
)
|
||||
|
||||
var flagSchema bool
|
||||
@ -32,12 +32,10 @@ func main() {
|
||||
ctx, cncl := signal.NotifyContext(context.Background(), os.Interrupt, unix.SIGTERM)
|
||||
defer cncl()
|
||||
|
||||
// This will be loaded by go-app courtesy of MustLoadConfigInto, which will
|
||||
// combine our sample configuration along with the embedded go-app AppConfig
|
||||
demoAppConfig := &config.DemoConfig{}
|
||||
|
||||
// Load configuration and setup logging
|
||||
ctx, demoApp := app.MustLoadConfigInto(ctx, demoAppConfig)
|
||||
// Load configuration and setup logging. The go-app framework
|
||||
// will handle loading config and environment into our demo
|
||||
// app config struct which embeds app.AooConfig
|
||||
ctx, demoApp := app.MustLoadConfigInto(ctx, &config.DemoConfig{})
|
||||
|
||||
// Print schema if that's all we have to do
|
||||
if flagSchema {
|
||||
@ -47,19 +45,16 @@ func main() {
|
||||
|
||||
log.Debug().Any("demoAppMergedConfig", demoApp).Msg("demo app config prepared")
|
||||
|
||||
// Prepare servers
|
||||
demoHTTP := demohttp.NewDemoHTTPServer(ctx, demoApp)
|
||||
|
||||
// Prepare app
|
||||
app := &app.App{
|
||||
AppContext: ctx,
|
||||
HTTP: &optshttp.AppHTTP{
|
||||
Funcs: []optshttp.HTTPFunc{
|
||||
{
|
||||
Path: "/test",
|
||||
HandlerFunc: func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotImplemented)
|
||||
w.Write([]byte("http test route"))
|
||||
},
|
||||
},
|
||||
},
|
||||
Ctx: ctx,
|
||||
HealthChecks: demoHTTP.GetHealthCheckFuncs(),
|
||||
Funcs: demoHTTP.GetHandleFuncs(),
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user