github.com/Jeffail/benthos/v3@v3.65.0/public/components/legacy/package.go (about)

     1  // Package legacy imports old legacy component definitions (and plugins), and
     2  // also walks them during init in order to register their docs and constructors
     3  // using the new APIs.
     4  package legacy
     5  
     6  import (
     7  	"github.com/Jeffail/benthos/v3/internal/bundle"
     8  	"github.com/Jeffail/benthos/v3/internal/docs"
     9  	"github.com/Jeffail/benthos/v3/lib/buffer"
    10  	"github.com/Jeffail/benthos/v3/lib/cache"
    11  	"github.com/Jeffail/benthos/v3/lib/input"
    12  	"github.com/Jeffail/benthos/v3/lib/metrics"
    13  	"github.com/Jeffail/benthos/v3/lib/output"
    14  	"github.com/Jeffail/benthos/v3/lib/processor"
    15  	"github.com/Jeffail/benthos/v3/lib/ratelimit"
    16  	"github.com/Jeffail/benthos/v3/lib/tracer"
    17  	"github.com/Jeffail/benthos/v3/lib/types"
    18  )
    19  
    20  func init() {
    21  	buffer.WalkConstructors(func(ctor buffer.ConstructorFunc, spec docs.ComponentSpec) {
    22  		if err := bundle.AllBuffers.Add(func(conf buffer.Config, mgr bundle.NewManagement) (buffer.Type, error) {
    23  			return ctor(conf, mgr, mgr.Logger(), mgr.Metrics())
    24  		}, spec); err != nil {
    25  			panic(err)
    26  		}
    27  	})
    28  	cache.WalkConstructors(func(ctor cache.ConstructorFunc, spec docs.ComponentSpec) {
    29  		if err := bundle.AllCaches.Add(func(conf cache.Config, mgr bundle.NewManagement) (types.Cache, error) {
    30  			return ctor(conf, mgr, mgr.Logger(), mgr.Metrics())
    31  		}, spec); err != nil {
    32  			panic(err)
    33  		}
    34  	})
    35  	input.WalkConstructors(func(ctor input.ConstructorFunc, spec docs.ComponentSpec) {
    36  		if err := bundle.AllInputs.Add(func(
    37  			bProc bool,
    38  			conf input.Config,
    39  			mgr bundle.NewManagement,
    40  			pipes ...types.PipelineConstructorFunc,
    41  		) (input.Type, error) {
    42  			return ctor(bProc, conf, mgr, mgr.Logger(), mgr.Metrics(), pipes...)
    43  		}, spec); err != nil {
    44  			panic(err)
    45  		}
    46  	})
    47  	metrics.WalkConstructors(func(ctor metrics.ConstructorFunc, spec docs.ComponentSpec) {
    48  		if err := bundle.AllMetrics.Add(bundle.MetricConstructor(ctor), spec); err != nil {
    49  			panic(err)
    50  		}
    51  	})
    52  	output.WalkConstructors(func(ctor output.ConstructorFunc, spec docs.ComponentSpec) {
    53  		if err := bundle.AllOutputs.Add(func(
    54  			conf output.Config,
    55  			mgr bundle.NewManagement,
    56  			pipes ...types.PipelineConstructorFunc,
    57  		) (output.Type, error) {
    58  			return ctor(conf, mgr, mgr.Logger(), mgr.Metrics(), pipes...)
    59  		}, spec); err != nil {
    60  			panic(err)
    61  		}
    62  	})
    63  	processor.WalkConstructors(func(ctor processor.ConstructorFunc, spec docs.ComponentSpec) {
    64  		if err := bundle.AllProcessors.Add(func(conf processor.Config, mgr bundle.NewManagement) (processor.Type, error) {
    65  			return ctor(conf, mgr, mgr.Logger(), mgr.Metrics())
    66  		}, spec); err != nil {
    67  			panic(err)
    68  		}
    69  	})
    70  	ratelimit.WalkConstructors(func(ctor ratelimit.ConstructorFunc, spec docs.ComponentSpec) {
    71  		if err := bundle.AllRateLimits.Add(func(conf ratelimit.Config, mgr bundle.NewManagement) (types.RateLimit, error) {
    72  			return ctor(conf, mgr, mgr.Logger(), mgr.Metrics())
    73  		}, spec); err != nil {
    74  			panic(err)
    75  		}
    76  	})
    77  	tracer.WalkConstructors(func(ctor tracer.ConstructorFunc, spec docs.ComponentSpec) {
    78  		if err := bundle.AllTracers.Add(bundle.TracerConstructor(ctor), spec); err != nil {
    79  			panic(err)
    80  		}
    81  	})
    82  }