2025-01-03 22:13:15 +00:00
|
|
|
// This template contains a simple
|
|
|
|
// app with OTEL bootstrap that will create an
|
|
|
|
// HTTP server configured by environment that exports
|
|
|
|
// spans and metrics to an OTEL collector if configured
|
|
|
|
// to do so. Will also stand up a prometheus metrics
|
|
|
|
// endpoint.
|
2025-01-04 02:09:40 +00:00
|
|
|
//
|
|
|
|
// Configuration and logger stored in context
|
2025-01-04 05:06:49 +00:00
|
|
|
// Reference implementation of the provided packages
|
2025-01-03 22:13:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2025-01-04 05:06:49 +00:00
|
|
|
"net/http"
|
2025-01-03 22:13:15 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
|
2025-01-04 02:09:40 +00:00
|
|
|
"github.com/rs/zerolog"
|
2025-01-04 05:06:49 +00:00
|
|
|
"go.opentelemetry.io/otel/trace"
|
2025-01-03 22:13:15 +00:00
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
|
2025-01-07 15:03:10 +00:00
|
|
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv"
|
2025-01-04 05:06:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
cfg *config.AppConfig
|
|
|
|
l *zerolog.Logger
|
|
|
|
tracer trace.Tracer
|
2025-01-03 22:13:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
ctx, cncl := signal.NotifyContext(context.Background(), os.Interrupt, unix.SIGTERM)
|
|
|
|
defer cncl()
|
|
|
|
|
2025-01-04 05:06:49 +00:00
|
|
|
// Load configuration and setup logging
|
2025-01-04 16:23:24 +00:00
|
|
|
ctx = app.MustSetupConfigAndLogging(ctx)
|
|
|
|
|
|
|
|
// Prepare app
|
|
|
|
app := &app.App{
|
|
|
|
AppContext: ctx,
|
|
|
|
HTTP: &app.AppHTTP{
|
|
|
|
Funcs: []srv.HTTPFunc{
|
|
|
|
{
|
|
|
|
Path: "/test",
|
|
|
|
HandlerFunc: func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
|
|
w.Write([]byte("http test route"))
|
|
|
|
},
|
|
|
|
},
|
2025-01-04 05:06:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2025-01-04 16:23:24 +00:00
|
|
|
// Launch app
|
|
|
|
app.MustRun()
|
2025-01-04 05:06:49 +00:00
|
|
|
|
2025-01-04 16:23:24 +00:00
|
|
|
// Wait for app to complete
|
|
|
|
// Perform any extra shutdown here
|
|
|
|
<-app.Done()
|
2025-01-04 05:06:49 +00:00
|
|
|
}
|