mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-20 20:47:16 +02:00
postgres: databroker storage backend (#3370)
* wip * storage: add filtering to SyncLatest * don't increment the record version, so intermediate changes are requested * databroker: add support for query filtering * fill server and record version * postgres: databroker storage backend * wip * serialize puts * add test * skip tests for macos * add test * return error from protojson * set data * exclude postgres from cover tests
This commit is contained in:
parent
550698b1ca
commit
1c2aad2de6
21 changed files with 1573 additions and 17 deletions
66
pkg/contextutil/contextutil.go
Normal file
66
pkg/contextutil/contextutil.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
// Package contextutil contains functions for working with contexts.
|
||||
package contextutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type mergedCtx struct {
|
||||
ctx1, ctx2 context.Context
|
||||
|
||||
doneCtx context.Context
|
||||
doneCancel context.CancelFunc
|
||||
}
|
||||
|
||||
// Merge merges two contexts into a single context.
|
||||
func Merge(ctx1, ctx2 context.Context) (context.Context, context.CancelFunc) {
|
||||
mc := &mergedCtx{
|
||||
ctx1: ctx1,
|
||||
ctx2: ctx2,
|
||||
}
|
||||
mc.doneCtx, mc.doneCancel = context.WithCancel(context.Background())
|
||||
go func() {
|
||||
select {
|
||||
case <-ctx1.Done():
|
||||
case <-ctx2.Done():
|
||||
case <-mc.doneCtx.Done():
|
||||
}
|
||||
mc.doneCancel()
|
||||
}()
|
||||
return mc, mc.doneCancel
|
||||
}
|
||||
|
||||
func (mc *mergedCtx) Deadline() (deadline time.Time, ok bool) {
|
||||
if deadline, ok = mc.ctx1.Deadline(); ok {
|
||||
return deadline, ok
|
||||
}
|
||||
if deadline, ok = mc.ctx2.Deadline(); ok {
|
||||
return deadline, ok
|
||||
}
|
||||
return mc.doneCtx.Deadline()
|
||||
}
|
||||
|
||||
func (mc *mergedCtx) Done() <-chan struct{} {
|
||||
return mc.doneCtx.Done()
|
||||
}
|
||||
|
||||
func (mc *mergedCtx) Err() error {
|
||||
if err := mc.ctx1.Err(); err != nil {
|
||||
return mc.ctx1.Err()
|
||||
}
|
||||
if err := mc.ctx2.Err(); err != nil {
|
||||
return mc.ctx2.Err()
|
||||
}
|
||||
return mc.doneCtx.Err()
|
||||
}
|
||||
|
||||
func (mc *mergedCtx) Value(key interface{}) interface{} {
|
||||
if value := mc.ctx1.Value(key); value != nil {
|
||||
return value
|
||||
}
|
||||
if value := mc.ctx2.Value(key); value != nil {
|
||||
return value
|
||||
}
|
||||
return mc.doneCtx.Value(key)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue