support runtime.ServeMux opts for grpc-gateway
All checks were successful
Build and Publish / release (push) Has been skipped
Build and Publish / check-chart (push) Successful in 10s
Build and Publish / helm-release (push) Has been skipped

This commit is contained in:
2025-03-25 17:05:59 -04:00
parent 1e481627e3
commit f201ac1fca
10 changed files with 78 additions and 6 deletions

View File

@ -29,6 +29,10 @@ type Opts struct {
KeepLast int
}
func (r *WeatherRecorder) Ping(ctx context.Context) error {
return r.recorder.Ping(ctx)
}
func MustNewWeatherRecorder(opts *Opts) *WeatherRecorder {
if opts.KeepLast < 1 {
opts.KeepLast = 1

View File

@ -25,6 +25,11 @@ type MemoryRecorder struct {
*sync.RWMutex
}
// No meaningful health check to do here
func (r *MemoryRecorder) Ping(ctx context.Context) error {
return nil
}
func (r *MemoryRecorder) Init(ctx context.Context, opts *recorders.RecorderOpts) {
if opts.RetainLast < 1 {
opts.RetainLast = DEF_RETAIN_LAST

View File

@ -20,4 +20,6 @@ func (n *NoopRecorder) Get(context.Context, *pb.GetWeatherRequest) ([]*weather.W
func (n *NoopRecorder) Count(context.Context) int { return 0 }
func (n *NoopRecorder) Ping(context.Context) error { return nil }
func (r *NoopRecorder) Name() string { return "no-op recorder" }

View File

@ -19,5 +19,6 @@ type Recorder interface {
Set(context.Context, *weather.WeatherUpdate) error
Get(context.Context, *pb.GetWeatherRequest) ([]*weather.WeatherUpdate, error)
Count(context.Context) int // Best Effort
Ping(context.Context) error
Name() string
}

View File

@ -36,6 +36,11 @@ type RedisRecorder struct {
*sync.RWMutex
}
func (r *RedisRecorder) Ping(ctx context.Context) error {
_, err := r.redis.Ping(ctx).Result()
return err
}
func (r *RedisRecorder) Init(ctx context.Context, opts *recorders.RecorderOpts) {
if opts.AppConfig.RecorderConfig.RedisConfig == nil {
panic("refusing to init redis recorder with no redisConfig")