Skip to content

Commit

Permalink
Use const instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schneider committed Jan 14, 2023
1 parent 7b4281c commit 4eecf2d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/configload/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func setOAuth2Backend(helper *helper, parent *hclsyntax.Body) (*hclsyntax.Body,

func checkTokenRequestLabels(trbs []*hclsyntax.Block, unique map[string]struct{}) error {
for _, trb := range trbs {
label := defaultNameLabel
label := config.DefaultNameLabel
dr := trb.DefRange()
r := &dr
if len(trb.Labels) > 0 {
Expand Down
8 changes: 4 additions & 4 deletions config/configload/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func refineEndpoints(helper *helper, endpoints config.Endpoints, checkPathPatter

for _, proxyConfig := range ep.Proxies {
if proxyConfig.Name == "" {
proxyConfig.Name = defaultNameLabel
proxyConfig.Name = config.DefaultNameLabel
}

names[proxyConfig.Name] = proxyConfig.HCLBody()
Expand All @@ -86,7 +86,7 @@ func refineEndpoints(helper *helper, endpoints config.Endpoints, checkPathPatter
}

if wsEnabled {
if proxyConfig.Name != defaultNameLabel {
if proxyConfig.Name != config.DefaultNameLabel {
return errors.Configuration.Message("websockets attribute or block is only allowed in a 'default' proxy block")
}
if proxyRequestLabelRequired || ep.Response != nil {
Expand All @@ -106,7 +106,7 @@ func refineEndpoints(helper *helper, endpoints config.Endpoints, checkPathPatter

for _, reqConfig := range ep.Requests {
if reqConfig.Name == "" {
reqConfig.Name = defaultNameLabel
reqConfig.Name = config.DefaultNameLabel
}

names[reqConfig.Name] = reqConfig.HCLBody()
Expand Down Expand Up @@ -143,7 +143,7 @@ func refineEndpoints(helper *helper, endpoints config.Endpoints, checkPathPatter
}
}

if _, ok := names[defaultNameLabel]; checkPathPattern && !ok && ep.Response == nil {
if _, ok := names[config.DefaultNameLabel]; checkPathPattern && !ok && ep.Response == nil {
return newDiagErr(&subject, "Missing a 'default' proxy or request definition, or a response block")
}

Expand Down
2 changes: 0 additions & 2 deletions config/configload/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ const (
spa = "spa"
tls = "tls"
tokenRequest = "beta_token_request"
// defaultNameLabel maps the hcl label attr 'name'.
defaultNameLabel = "default"
)

var defaultsConfig *config.Defaults
Expand Down
3 changes: 2 additions & 1 deletion config/configload/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"
"strings"

"github.com/avenga/couper/config"
"github.com/avenga/couper/eval"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
Expand Down Expand Up @@ -535,7 +536,7 @@ func mergeDefinitions(bodies []*hclsyntax.Body) (*hclsyntax.Block, map[string]*h

delete(innerBlock.Body.Attributes, "name")
} else {
innerBlock.Labels[0] = defaultNameLabel
innerBlock.Labels[0] = config.DefaultNameLabel
}

proxiesList[label] = innerBlock
Expand Down
4 changes: 4 additions & 0 deletions config/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package config

// DefaultNameLabel maps the hcl label attr 'name'.
const DefaultNameLabel = "default"
3 changes: 2 additions & 1 deletion logging/upstream_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/zclconf/go-cty/cty"

"github.com/avenga/couper/config"
"github.com/avenga/couper/config/env"
"github.com/avenga/couper/config/request"
"github.com/avenga/couper/errors"
Expand Down Expand Up @@ -162,7 +163,7 @@ func (u *UpstreamLog) RoundTrip(req *http.Request) (*http.Response, error) {
}
}

if name, ok := requestFields["name"].(string); ok && name != "default" {
if name, ok := requestFields["name"].(string); ok && name != config.DefaultNameLabel {
serverTimingsKey += "_" + name
}

Expand Down

0 comments on commit 4eecf2d

Please sign in to comment.