add metadata prefooter
This commit is contained in:
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
@ -15,26 +16,45 @@ func main() {
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{}))
|
||||
log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
||||
Level: slog.LevelDebug,
|
||||
ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr {
|
||||
if a.Key == slog.TimeKey {
|
||||
a.Value = slog.Int64Value(a.Value.Time().Unix())
|
||||
}
|
||||
|
||||
version, commit, bt := kurious.Version(), kurious.Commit(), kurious.BuildTime()
|
||||
pid := os.Getpid()
|
||||
return a
|
||||
},
|
||||
}))
|
||||
|
||||
log.InfoContext(
|
||||
ctx, "running app",
|
||||
slog.Int("pid", pid),
|
||||
slog.String("version", version),
|
||||
slog.String("commit", commit),
|
||||
slog.Time("build_time", bt),
|
||||
)
|
||||
version, commit, bt := kurious.Version(), kurious.Commit(), kurious.BuildTime()
|
||||
pid := os.Getpid()
|
||||
|
||||
client := sravni.NewClient(log, true)
|
||||
meta, err := client.GetMetaInfo(ctx)
|
||||
if err != nil {
|
||||
log.ErrorContext(ctx, "unable to get meta info", slog.Any("error", err))
|
||||
}
|
||||
log.InfoContext(
|
||||
ctx, "running app",
|
||||
slog.Int("pid", pid),
|
||||
slog.String("version", version),
|
||||
slog.String("commit", commit),
|
||||
slog.Time("build_time", bt),
|
||||
)
|
||||
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
_ = enc.Encode(meta)
|
||||
err := app(ctx, log)
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "unable to run app", slog.Any("error", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func app(ctx context.Context, log *slog.Logger) error {
|
||||
client, err := sravni.NewClient(ctx, log, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("making new client: %w", err)
|
||||
}
|
||||
|
||||
meta := client.GetMainPageState()
|
||||
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
|
||||
return enc.Encode(meta)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user