MCPcopy Create free account
hub / github.com/pace/bricks / main

Function main

tools/testserver/main.go:67–241  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67func main() {
68 db := postgres.NewDB(context.Background())
69 rdb := redis.Client()
70 cdb, err := couchdb.DefaultDatabase()
71 if err != nil {
72 log.Fatal(err)
73 }
74 _, err = objstore.Client()
75 if err != nil {
76 log.Fatal(err)
77 }
78
79 ap, err := failover.NewActivePassive("testserver", time.Second*10, rdb)
80 if err != nil {
81 log.Fatal(err)
82 }
83 go ap.Run(log.WithContext(context.Background())) // nolint: errcheck
84
85 h := pacehttp.Router()
86 servicehealthcheck.RegisterHealthCheckFunc("fail-50", func(ctx context.Context) (r servicehealthcheck.HealthCheckResult) {
87 if time.Now().Unix()%2 == 0 {
88 panic("boom")
89 }
90 r.Msg = "Foo"
91 r.State = servicehealthcheck.Ok
92 return
93 })
94
95 h.Handle("/pay/beta/test", simple.Router(new(TestService)))
96
97 h.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
98 ctx := r.Context()
99
100 span := sentry.StartSpan(ctx, "TestHandler")
101 defer span.Finish()
102
103 ctx = span.Context()
104
105 // do dummy database query
106 var result struct {
107 Calc int //nolint
108 }
109 res, err := db.NewSelect().Model(&result).ColumnExpr("? + ? AS Calc", 10, 10).Exec(ctx)
110 if err != nil {
111 log.Ctx(ctx).Debug().Err(err).Msg("Calc failed")
112 return
113 }
114
115 count, err := res.RowsAffected()
116 if err != nil {
117 log.Ctx(ctx).Debug().Err(err).Msg("RowsAffected failed")
118 return
119 }
120
121 log.Ctx(ctx).Debug().Int64("rows_affected", count).Msg("Calc done")
122
123 // do dummy redis query
124 crdb := redis.WithContext(ctx, rdb)

Callers

nothing calls this directly

Calls 15

RunMethod · 0.95
AddMethod · 0.95
SubstractMethod · 0.95
NewDBFunction · 0.92
ClientFunction · 0.92
DefaultDatabaseFunction · 0.92
FatalFunction · 0.92
ClientFunction · 0.92
NewActivePassiveFunction · 0.92
WithContextFunction · 0.92
RegisterHealthCheckFuncFunction · 0.92
RouterFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…