Border0 service discovery framework and library.
Assume that the following variables are defined as follows:
ctx := context.Background()
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
// handle error
}
Then,
// initialize a new one off engine
engine := engines.NewOneOffEngine(
engines.OneOffEngineOptionWithDiscoverers(
discoverers.NewAwsEc2Discoverer(cfg),
discoverers.NewAwsEcsDiscoverer(cfg),
discoverers.NewAwsRdsDiscoverer(cfg),
// ... LAN, docker, k8s, gcp compute, azure vms, etc ...
),
)
// create channels for discovery results
results := make(chan *discovery.Result, 10)
// run engine
go engine.Run(ctx, results)
// process results as they come in
for result := range results {
// ... do something ...
}
Assume that the following variables are defined as follows:
Assume that ctx (type
context.Context
) is defined by some upstream code
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
// handle error
}
Then,
// initialize a new continuous engine
engine := engines.NewContinuousEngine(
engines.WithDiscoverer(
discoverers.NewAwsEc2Discoverer(cfg),
engines.WithInitialInterval(time.Second*2),
),
engines.WithDiscoverer(
discoverers.NewAwsEcsDiscoverer(cfg),
engines.WithInitialInterval(time.Second*2),
),
engines.WithDiscoverer(
discoverers.NewAwsRdsDiscoverer(cfg),
engines.WithInitialInterval(time.Second*2),
),
)
// create channels for discovery results
results := make(chan *discovery.Result, 10)
// run engine
go engine.Run(ctx, results)
// process results as they come in
for result := range results {
// ... do something ...
}
Assume that the following variables are defined as follows:
awsRegions := []string{"us-east-1", "us-east-2", "us-west-2", "eu-west-1"}
ctx := context.Background()
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
// handle error
}
Then,
// define an ec2 discoverer for each region
ds := []discovery.Discoverer{}
for _, region := range regions {
cfg.Region = region
ds = append(ds, discoverers.NewAwsEc2Discoverer(cfg))
}
// initialize a new one off engine with the discoverers
engine := engines.NewOneOffEngine(
engines.OneOffEngineOptionWithDiscoverers(ds...),
)
// create channels for discovery results
results := make(chan *discovery.Result, 10)
// run engine
go engine.Run(ctx, results)
// process results as they come in
for result := range results {
// ... do something ...
}