From 17a5bc51ca5e7db67a72c14599af939225cc1941 Mon Sep 17 00:00:00 2001 From: Antonio Navarro Perez Date: Mon, 8 Feb 2021 18:36:53 +0100 Subject: [PATCH] Add NopSchemator and NopSerializer Signed-off-by: Antonio Navarro Perez --- broadcast.go | 11 +++++++++++ disco/disco.go | 28 ++++++++++++++++++++++++++++ holder.go | 6 ++++++ 3 files changed, 45 insertions(+) diff --git a/broadcast.go b/broadcast.go index 915108a56..8ed654b7b 100644 --- a/broadcast.go +++ b/broadcast.go @@ -27,6 +27,17 @@ type Serializer interface { Unmarshal([]byte, Message) error } +// NopSerializer represents a Serializer that doesn't do anything. +var NopSerializer Serializer = &nopSerializer{} + +type nopSerializer struct{} + +// Marshal A no-op implementation of Serializer Marshall method. +func (*nopSerializer) Marshal(Message) ([]byte, error) { return nil, nil } + +// Unmarshal A no-op implementation of Serializer Unmarshal method. +func (*nopSerializer) Unmarshal([]byte, Message) error { return nil } + // broadcaster is an interface for broadcasting messages. type broadcaster interface { SendSync(Message) error diff --git a/disco/disco.go b/disco/disco.go index 03443d384..06187da56 100644 --- a/disco/disco.go +++ b/disco/disco.go @@ -233,3 +233,31 @@ func (n *nopSharder) AddShards(ctx context.Context, index, field string, shards func (n *nopSharder) RemoveShard(ctx context.Context, index, field string, shard uint64) error { return nil } + +// NopSchemator represents a Schemator that doesn't do anything. +var NopSchemator Schemator = &nopSchemator{} + +type nopSchemator struct{} + +// Schema is a no-op implementation of the Schemator Schema method. +func (*nopSchemator) Schema(ctx context.Context) (map[string]*Index, error) { return nil, nil } + +// Index is a no-op implementation of the Schemator Index method. +func (*nopSchemator) Index(ctx context.Context, name string) ([]byte, error) { return nil, nil } + +// CreateIndex is a no-op implementation of the Schemator CreateIndex method. +func (*nopSchemator) CreateIndex(ctx context.Context, name string, val []byte) error { return nil } + +// DeleteIndex is a no-op implementation of the Schemator DeleteIndex method. +func (*nopSchemator) DeleteIndex(ctx context.Context, name string) error { return nil } + +// Field is a no-op implementation of the Schemator Field method. +func (*nopSchemator) Field(ctx context.Context, index, field string) ([]byte, error) { return nil, nil } + +// CreateField is a no-op implementation of the Schemator CreateField method. +func (*nopSchemator) CreateField(ctx context.Context, index, field string, val []byte) error { + return nil +} + +// DeleteField is a no-op implementation of the Schemator DeleteField method. +func (*nopSchemator) DeleteField(ctx context.Context, index, field string) error { return nil } diff --git a/holder.go b/holder.go index 333bcd189..47ca88254 100644 --- a/holder.go +++ b/holder.go @@ -213,6 +213,8 @@ type HolderConfig struct { OpenTransactionStore OpenTransactionStoreFunc OpenIDAllocator OpenIDAllocatorFunc TranslationSyncer TranslationSyncer + Serializer Serializer + Schemator disco.Schemator CacheFlushInterval time.Duration StatsClient stats.StatsClient NewAttrStore func(string) AttrStore @@ -232,6 +234,8 @@ func DefaultHolderConfig() *HolderConfig { OpenTransactionStore: OpenInMemTransactionStore, OpenIDAllocator: func(string) (*idAllocator, error) { return &idAllocator{}, nil }, TranslationSyncer: NopTranslationSyncer, + Serializer: NopSerializer, + Schemator: disco.NopSchemator, CacheFlushInterval: defaultCacheFlushInterval, StatsClient: stats.NopStatsClient, NewAttrStore: newNopAttrStore, @@ -270,6 +274,8 @@ func NewHolder(path string, cfg *HolderConfig) *Holder { OpenTransactionStore: cfg.OpenTransactionStore, OpenIDAllocator: cfg.OpenIDAllocator, translationSyncer: cfg.TranslationSyncer, + serializer: cfg.Serializer, + schemator: cfg.Schemator, Logger: cfg.Logger, Opts: HolderOpts{StorageBackend: cfg.StorageConfig.Backend, RowcacheOn: cfg.RowcacheOn},