update to new go-app
This commit is contained in:
47
main.go
47
main.go
@ -11,37 +11,45 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv"
|
||||
optshttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-http-server-with-otel/pkg/config"
|
||||
)
|
||||
|
||||
var (
|
||||
cfg *config.AppConfig
|
||||
l *zerolog.Logger
|
||||
tracer trace.Tracer
|
||||
)
|
||||
var flagSchema bool
|
||||
|
||||
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 = app.MustSetupConfigAndLogging(ctx)
|
||||
ctx, demoApp := app.MustLoadConfigInto(ctx, demoAppConfig)
|
||||
fmt.Printf("Demo App Config:\n\n%+v\n", *demoApp)
|
||||
|
||||
// Print schema if that's all we have to do
|
||||
if flagSchema {
|
||||
printSchema()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Prepare app
|
||||
app := &app.App{
|
||||
AppContext: ctx,
|
||||
HTTP: &app.AppHTTP{
|
||||
Funcs: []srv.HTTPFunc{
|
||||
HTTP: &optshttp.AppHTTP{
|
||||
Funcs: []optshttp.HTTPFunc{
|
||||
{
|
||||
Path: "/test",
|
||||
HandlerFunc: func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -60,3 +68,18 @@ func main() {
|
||||
// Perform any extra shutdown here
|
||||
<-app.Done()
|
||||
}
|
||||
|
||||
// flag.Parse will be called by go-app
|
||||
func init() {
|
||||
flag.BoolVar(&flagSchema, "schema", false, "generate json schema and exit")
|
||||
}
|
||||
|
||||
func printSchema() {
|
||||
bytes, err := app.CustomSchema(&config.DemoConfig{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(bytes))
|
||||
os.Exit(0)
|
||||
}
|
||||
|
Reference in New Issue
Block a user