forked from dotandev/hintents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
87 lines (73 loc) · 2.14 KB
/
main.go
File metadata and controls
87 lines (73 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2026 Erst Users
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"runtime/debug"
// "github.com/dotandev/hintents/internal/cmd"
"github.com/dotandev/hintents/internal/cmd"
"github.com/dotandev/hintents/internal/config"
"github.com/dotandev/hintents/internal/crashreport"
)
// Build-time variables injected via -ldflags.
var (
version = "dev"
commitSHA = "unknown"
)
// ─── Example RPC handler ──────────────────────────────────────────────────────
func rpcHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]interface{}{
"jsonrpc": "2.0",
"result": "0xdeadbeef",
"id": 1,
})
}
func healthzHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "ok")
}
func main() {
ctx := context.Background()
// Load config to determine whether crash reporting is opted in.
cfg, err := config.LoadConfig()
if err != nil {
// Non-fatal: fall back to a reporter that is disabled by default.
cfg = config.DefaultConfig()
}
reporter := crashreport.New(crashreport.Config{
Enabled: cfg.CrashReporting,
SentryDSN: cfg.CrashSentryDSN,
Endpoint: cfg.CrashEndpoint,
Version: version,
CommitSHA: commitSHA,
})
// Catch any unrecovered panic, report it, then re-panic.
defer reporter.HandlePanic(ctx, "erst")
execute := func() error {
execErr := cmd.Execute()
if execErr != nil && reporter.IsEnabled() && !cmd.IsInterrupted(execErr) {
// Report fatal command errors that were not recovered as panics.
stack := debug.Stack()
_ = reporter.Send(ctx, execErr, stack, "erst")
}
return execErr
}
os.Exit(run(execute, os.Stderr))
}
func run(execute func() error, stderr io.Writer) int {
if err := execute(); err != nil {
if cmd.IsInterrupted(err) {
fmt.Fprintln(stderr, "Interrupted. Shutting down...")
return cmd.InterruptExitCode
}
fmt.Fprintf(stderr, "Error: %v\n", err)
return 1
}
return 0
}