mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-30 17:37:25 +02:00
grpc: remove ptypes references (#3078)
This commit is contained in:
parent
35f697e491
commit
1342523cda
13 changed files with 83 additions and 177 deletions
|
@ -5,11 +5,48 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/grpcutil"
|
||||
"github.com/pomerium/pomerium/pkg/protoutil"
|
||||
)
|
||||
|
||||
//go:generate go run github.com/golang/mock/mockgen -source=databroker.pb.go -destination ./mock_databroker/databroker.pb.go DataBrokerServiceClient
|
||||
//go:generate go run github.com/golang/mock/mockgen -source=leaser.go -destination ./mock_databroker/leaser.go LeaserHandler
|
||||
|
||||
type recordObject interface {
|
||||
proto.Message
|
||||
GetId() string
|
||||
}
|
||||
|
||||
// NewRecord creates a new Record.
|
||||
func NewRecord(object recordObject) *Record {
|
||||
return &Record{
|
||||
Type: grpcutil.GetTypeURL(object),
|
||||
Id: object.GetId(),
|
||||
Data: protoutil.NewAny(object),
|
||||
}
|
||||
}
|
||||
|
||||
// Get gets a record from the databroker and unmarshals it into the object.
|
||||
func Get(ctx context.Context, client DataBrokerServiceClient, object recordObject) error {
|
||||
res, err := client.Get(ctx, &GetRequest{
|
||||
Type: grpcutil.GetTypeURL(object),
|
||||
Id: object.GetId(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return res.GetRecord().GetData().UnmarshalTo(object)
|
||||
}
|
||||
|
||||
// Put puts a record into the databroker.
|
||||
func Put(ctx context.Context, client DataBrokerServiceClient, object recordObject) (*PutResponse, error) {
|
||||
return client.Put(ctx, &PutRequest{Record: NewRecord(object)})
|
||||
}
|
||||
|
||||
// ApplyOffsetAndLimit applies the offset and limit to the list of records.
|
||||
func ApplyOffsetAndLimit(all []*Record, offset, limit int) (records []*Record, totalCount int) {
|
||||
records = all
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue