github.com/Jeffail/benthos/v3@v3.65.0/lib/stream/manager/namespaced_manager.go (about)

     1  package manager
     2  
     3  import (
     4  	"errors"
     5  	"net/http"
     6  	"path"
     7  
     8  	"github.com/Jeffail/benthos/v3/lib/types"
     9  )
    10  
    11  //------------------------------------------------------------------------------
    12  
    13  // TODO: V4 Delete this
    14  
    15  // NamespacedManager is a types.Manager implementation that wraps an underlying
    16  // implementation with a namespace that prefixes registered endpoints, etc.
    17  type NamespacedManager struct {
    18  	ns  string
    19  	mgr types.Manager
    20  }
    21  
    22  // RegisterEndpoint registers a server wide HTTP endpoint.
    23  func (n *NamespacedManager) RegisterEndpoint(p, desc string, h http.HandlerFunc) {
    24  	n.mgr.RegisterEndpoint(path.Join(n.ns, p), desc, h)
    25  }
    26  
    27  // GetOutput attempts to find a service wide output by its name.
    28  func (n *NamespacedManager) GetOutput(name string) (types.OutputWriter, error) {
    29  	// TODO: V4 Simplify this.
    30  	if outProv, ok := n.mgr.(interface {
    31  		GetOutput(name string) (types.OutputWriter, error)
    32  	}); ok {
    33  		return outProv.GetOutput(name)
    34  	}
    35  	return nil, errors.New("wrapped manager does not support output resources")
    36  }
    37  
    38  // GetInput attempts to find a service wide input by its name.
    39  func (n *NamespacedManager) GetInput(name string) (types.Input, error) {
    40  	// TODO: V4 Simplify this.
    41  	if inProv, ok := n.mgr.(interface {
    42  		GetInput(name string) (types.Input, error)
    43  	}); ok {
    44  		return inProv.GetInput(name)
    45  	}
    46  	return nil, errors.New("wrapped manager does not support input resources")
    47  }
    48  
    49  // GetCache attempts to find a service wide cache by its name.
    50  func (n *NamespacedManager) GetCache(name string) (types.Cache, error) {
    51  	return n.mgr.GetCache(name)
    52  }
    53  
    54  // GetCondition attempts to find a service wide condition by its name.
    55  func (n *NamespacedManager) GetCondition(name string) (types.Condition, error) {
    56  	return n.mgr.GetCondition(name)
    57  }
    58  
    59  // GetProcessor attempts to find a service wide processor by its name.
    60  func (n *NamespacedManager) GetProcessor(name string) (types.Processor, error) {
    61  	// TODO: V4 Simplify this.
    62  	if procProv, ok := n.mgr.(interface {
    63  		GetProcessor(name string) (types.Processor, error)
    64  	}); ok {
    65  		return procProv.GetProcessor(name)
    66  	}
    67  	return nil, errors.New("wrapped manager does not support processor resources")
    68  }
    69  
    70  // GetRateLimit attempts to find a service wide rate limit by its name.
    71  func (n *NamespacedManager) GetRateLimit(name string) (types.RateLimit, error) {
    72  	return n.mgr.GetRateLimit(name)
    73  }
    74  
    75  // GetPlugin attempts to find a service wide resource plugin by its name.
    76  func (n *NamespacedManager) GetPlugin(name string) (interface{}, error) {
    77  	return n.mgr.GetPlugin(name)
    78  }
    79  
    80  // GetPipe returns a named pipe transaction channel.
    81  func (n *NamespacedManager) GetPipe(name string) (<-chan types.Transaction, error) {
    82  	// Pipes are always absolute.
    83  	return n.mgr.GetPipe(name)
    84  }
    85  
    86  // SetPipe sets a named pipe.
    87  func (n *NamespacedManager) SetPipe(name string, t <-chan types.Transaction) {
    88  	// Pipes are always absolute.
    89  	n.mgr.SetPipe(name, t)
    90  }
    91  
    92  // UnsetPipe unsets a named pipe.
    93  func (n *NamespacedManager) UnsetPipe(name string, t <-chan types.Transaction) {
    94  	// Pipes are always absolute.
    95  	n.mgr.UnsetPipe(name, t)
    96  }
    97  
    98  // GetUnderlying returns the underlying types.Manager implementation.
    99  func (n *NamespacedManager) GetUnderlying() types.Manager {
   100  	return n.mgr
   101  }
   102  
   103  //------------------------------------------------------------------------------