Skip to content

Commit

Permalink
feat: Add GetDestinationNamesForSource
Browse files Browse the repository at this point in the history
  • Loading branch information
yevgenypats committed May 5, 2023
1 parent 7aa2461 commit aaa3e0d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw=
github.com/thoas/go-funk v0.9.3/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
Expand Down
12 changes: 12 additions & 0 deletions specs/spec_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/ghodss/yaml"
"golang.org/x/exp/slices"
)

type SpecReader struct {
Expand Down Expand Up @@ -163,6 +164,17 @@ func (r *SpecReader) GetDestinationByName(name string) *Destination {
return r.destinationsMap[name]
}

func (r *SpecReader) GetDestinationNamesForSource(name string) []string {
var destinations []string
source := r.sourcesMap[name]
for _, destinationName := range source.Destinations {
if slices.Contains(source.Destinations, destinationName) {
destinations = append(destinations, r.destinationsMap[destinationName].Name)
}
}
return destinations
}

func NewSpecReader(paths []string) (*SpecReader, error) {
reader := &SpecReader{
sourcesMap: make(map[string]*Source),
Expand Down

0 comments on commit aaa3e0d

Please sign in to comment.