61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
"os/signal"
|
|
|
|
"git.loyso.art/frx/kurious"
|
|
"git.loyso.art/frx/kurious/internal/infrastructure/interfaceadapters/courses/sravni"
|
|
)
|
|
|
|
func main() {
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
|
defer cancel()
|
|
|
|
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())
|
|
}
|
|
|
|
return a
|
|
},
|
|
}))
|
|
|
|
version, commit, bt := kurious.Version(), kurious.Commit(), kurious.BuildTime()
|
|
pid := os.Getpid()
|
|
|
|
log.InfoContext(
|
|
ctx, "running app",
|
|
slog.Int("pid", pid),
|
|
slog.String("version", version),
|
|
slog.String("commit", commit),
|
|
slog.Time("build_time", bt),
|
|
)
|
|
|
|
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)
|
|
}
|