Skip to content

Commit

Permalink
Tidy code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Baliedge committed Aug 1, 2023
1 parent 776fca4 commit 8f710b2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
12 changes: 5 additions & 7 deletions datamodel/low/v2/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,18 @@ func (p *Paths) Build(root *yaml.Node, idx *index.SpecIndex) error {
root = utils.NodeAlias(root)
utils.CheckForMergeNodes(root)
p.Extensions = low.ExtractExtensions(root)
// skip := false
// var currentNode *yaml.Node

// Translate YAML nodes to pathsMap using `TranslatePipeline`.
type pathBuildResult struct {
key low.KeyReference[string]
value low.ValueReference[*PathItem]
}
type nodeItem struct {
type buildInput struct {
currentNode *yaml.Node
pathNode *yaml.Node
}
pathsMap := make(map[low.KeyReference[string]]low.ValueReference[*PathItem])
in := make(chan nodeItem)
in := make(chan buildInput)
out := make(chan pathBuildResult)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -102,7 +100,7 @@ func (p *Paths) Build(root *yaml.Node, idx *index.SpecIndex) error {
}

select {
case in <- nodeItem{
case in <- buildInput{
currentNode: currentNode,
pathNode: pathNode,
}:
Expand Down Expand Up @@ -131,7 +129,7 @@ func (p *Paths) Build(root *yaml.Node, idx *index.SpecIndex) error {
}
}()

translateFunc := func(value nodeItem) (retval pathBuildResult, _ error) {
translateFunc := func(value buildInput) (retval pathBuildResult, _ error) {
pNode := value.pathNode
cNode := value.currentNode
path := new(PathItem)
Expand All @@ -151,7 +149,7 @@ func (p *Paths) Build(root *yaml.Node, idx *index.SpecIndex) error {
},
}, nil
}
err := datamodel.TranslatePipeline[nodeItem, pathBuildResult](in, out, translateFunc)
err := datamodel.TranslatePipeline[buildInput, pathBuildResult](in, out, translateFunc)
wg.Wait()
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions datamodel/low/v3/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type componentBuildResult[T any] struct {
value low.ValueReference[T]
}

type inputValue struct {
type componentInput struct {
node *yaml.Node
currentLabel *yaml.Node
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
in := make(chan inputValue)
in := make(chan componentInput)
out := make(chan componentBuildResult[T])
var wg sync.WaitGroup
wg.Add(2) // input and output goroutines.
Expand All @@ -257,7 +257,7 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.
}

select {
case in <- inputValue{
case in <- componentInput{
node: node,
currentLabel: currentLabel,
}:
Expand All @@ -278,7 +278,7 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.
}()

// Translate.
translateFunc := func(value inputValue) (componentBuildResult[T], error) {
translateFunc := func(value componentInput) (componentBuildResult[T], error) {
var n T = new(N)
currentLabel := value.currentLabel
node := value.node
Expand Down Expand Up @@ -311,7 +311,7 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.
},
}, nil
}
err := datamodel.TranslatePipeline[inputValue, componentBuildResult[T]](in, out, translateFunc)
err := datamodel.TranslatePipeline[componentInput, componentBuildResult[T]](in, out, translateFunc)
wg.Wait()
if err != nil {
return emptyResult, err
Expand Down
20 changes: 10 additions & 10 deletions datamodel/low/v3/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ func (p *Paths) Build(root *yaml.Node, idx *index.SpecIndex) error {

// Translate YAML nodes to pathsMap using `TranslatePipeline`.
type buildResult struct {
k low.KeyReference[string]
v low.ValueReference[*PathItem]
key low.KeyReference[string]
value low.ValueReference[*PathItem]
}
type inputValue struct {
type buildInput struct {
currentNode *yaml.Node
pathNode *yaml.Node
}
pathsMap := make(map[low.KeyReference[string]]low.ValueReference[*PathItem])
in := make(chan inputValue)
in := make(chan buildInput)
out := make(chan buildResult)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -107,7 +107,7 @@ func (p *Paths) Build(root *yaml.Node, idx *index.SpecIndex) error {
}

select {
case in <- inputValue{
case in <- buildInput{
currentNode: currentNode,
pathNode: pathNode,
}:
Expand All @@ -129,15 +129,15 @@ func (p *Paths) Build(root *yaml.Node, idx *index.SpecIndex) error {
if !ok {
return
}
pathsMap[result.k] = result.v
pathsMap[result.key] = result.value
case <-ctx.Done():
return

Check warning on line 134 in datamodel/low/v3/paths.go

View check run for this annotation

Codecov / codecov/patch

datamodel/low/v3/paths.go#L134

Added line #L134 was not covered by tests
}
}
}()

err := datamodel.TranslatePipeline[inputValue, buildResult](in, out,
func(value inputValue) (buildResult, error) {
err := datamodel.TranslatePipeline[buildInput, buildResult](in, out,
func(value buildInput) (buildResult, error) {
pNode := value.pathNode
cNode := value.currentNode

Expand Down Expand Up @@ -170,11 +170,11 @@ func (p *Paths) Build(root *yaml.Node, idx *index.SpecIndex) error {
}

return buildResult{
k: low.KeyReference[string]{
key: low.KeyReference[string]{
Value: cNode.Value,
KeyNode: cNode,
},
v: low.ValueReference[*PathItem]{
value: low.ValueReference[*PathItem]{
Value: path,
ValueNode: pNode,
},
Expand Down

0 comments on commit 8f710b2

Please sign in to comment.