github.com/ethersphere/bee/v2@v2.2.0/pkg/feeds/factory/factory.go (about)

     1  // Copyright 2021 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package factory
     6  
     7  import (
     8  	"github.com/ethersphere/bee/v2/pkg/feeds"
     9  	"github.com/ethersphere/bee/v2/pkg/feeds/epochs"
    10  	"github.com/ethersphere/bee/v2/pkg/feeds/sequence"
    11  	storage "github.com/ethersphere/bee/v2/pkg/storage"
    12  )
    13  
    14  type factory struct {
    15  	storage.Getter
    16  }
    17  
    18  func New(getter storage.Getter) feeds.Factory {
    19  	return &factory{getter}
    20  }
    21  
    22  func (f *factory) NewLookup(t feeds.Type, feed *feeds.Feed) (feeds.Lookup, error) {
    23  	switch t {
    24  	case feeds.Sequence:
    25  		return sequence.NewAsyncFinder(f.Getter, feed), nil
    26  	case feeds.Epoch:
    27  		return epochs.NewAsyncFinder(f.Getter, feed), nil
    28  	}
    29  
    30  	return nil, feeds.ErrFeedTypeNotFound
    31  }