Skip to content

Commit

Permalink
BUILD/MAJOR: go: upgrade go to 1.23 and client-native
Browse files Browse the repository at this point in the history
Includes changes to mimetypes in handlers for general storage and raw.
Alse removal of unused enum on tcp-request and tcp-response.
  • Loading branch information
mjuraga committed Sep 20, 2024
1 parent 0d5180c commit e7f56c0
Show file tree
Hide file tree
Showing 25 changed files with 156 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_BASE_IMAGE: $CI_REGISTRY_GO/haproxy-debian
BATS_VERSION: v1.4.1
GO_VERSION: "1.22"
GO_VERSION: "1.23"
DOCKER_VERSION: "26.0"

diff:
Expand Down
17 changes: 5 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ linters:
disable:
- dupl
- exhaustive
- exhaustivestruct
- funlen
- gci
- gochecknoglobals
- gocognit
- goconst
- gocyclo
- godot
- goerr113
- gomnd
- lll
- nestif
- nlreturn
Expand All @@ -41,18 +38,9 @@ linters:
- paralleltest
- testpackage
- varnamelen
- nosnakecase
- exhaustruct
- nonamedreturns
- forcetypeassert
- golint #deprecated
- varcheck #deprecated
- ifshort #deprecated
- structcheck #deprecated
- maligned #deprecated
- scopelint #deprecated
- interfacer #deprecated
- deadcode #deprecated
- rowserrcheck #rowserrcheck is disabled because of generics
- sqlclosecheck #rowserrcheck is disabled because of generics
- wastedassign #rowserrcheck is disabled because of generics
Expand All @@ -71,6 +59,11 @@ linters:
- gocritic
- tagalign
- depguard
- mnd
- gomnd
- err113
- execinquery
- exportloopref

issues:
exclude:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT_MODIFIED=${GIT_MODIFIED1}${GIT_MODIFIED2}
SWAGGER_VERSION=${shell curl -s https://raw.githubusercontent.com/haproxytech/client-native/master/Makefile | grep SWAGGER_VERSION -m 1 | awk -F"=" '{print $$2}'}
BUILD_DATE=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
CGO_ENABLED?=0
GOLANGCI_LINT_VERSION=1.57.1
GOLANGCI_LINT_VERSION=1.61.0

all: update clean build

Expand Down
2 changes: 1 addition & 1 deletion configuration/dataplane_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c *Configuration) copyClusterToConfiguration(dapiStorageCluster *storagety
if dapiStorageCluster.ClusterID != nil && !misc.HasOSArg("", "", "") {
c.Cluster.ClusterID.Store(*dapiStorageCluster.ClusterID)
}
if dapiStorageCluster.ClusterLogTargets != nil && len(dapiStorageCluster.ClusterLogTargets) > 0 {
if len(dapiStorageCluster.ClusterLogTargets) > 0 {
c.Cluster.ClusterLogTargets = dapiStorageCluster.ClusterLogTargets
}
}
Expand Down
12 changes: 6 additions & 6 deletions configuration/map_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,29 @@ func equalSomeEntries(fEntries, rEntries models.MapEntries, index ...int) bool {
return false
}

max := 0
var maximum int
switch l := len(rEntries); {
case l > 19:
for i := l - 20; i < l; i++ {
if rEntries[i].Key != fEntries[i].Key || rEntries[i].Value != fEntries[i].Value {
return false
}
}
max = l - 19
maximum = l - 19
case l == 0:
return true
default:
max = l
maximum = l
}

maxRandom := 10
if max < 10 {
maxRandom = max
if maximum < 10 {
maxRandom = maximum
}

for range maxRandom {
// There's no need for strong number generation, here, just need for performance
r := rand.Intn(max)
r := rand.Intn(maximum)
if len(index) > 0 {
r = index[0]
}
Expand Down
6 changes: 3 additions & 3 deletions configuration/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,20 @@ func AuthenticateUser(user string, pass string) (interface{}, error) {
if strings.HasPrefix(u.Password, "\"${") && strings.HasSuffix(u.Password, "}\"") {
userPass = os.Getenv(misc.ExtractEnvVar(userPass))
if userPass == "" {
return nil, api_errors.New(401, fmt.Sprintf("%s %s", "can not read password from env variable:", u.Password))
return nil, api_errors.New(401, "%s %s", "can not read password from env variable:", u.Password)
}
}

if u.IsInsecure {
if pass == userPass {
return user, nil
}
return nil, api_errors.New(401, fmt.Sprintf("%s %s", "invalid password:", pass))
return nil, api_errors.New(401, "%s %s", "invalid password:", pass)
}
if checkPassword(pass, userPass) {
return user, nil
}
return nil, api_errors.New(401, fmt.Sprintf("%s %s", "invalid password:", pass))
return nil, api_errors.New(401, "%s %s", "invalid password:", pass)
}

func checkPassword(pass, storedPass string) bool {
Expand Down
18 changes: 9 additions & 9 deletions configure_data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import (
"github.com/haproxytech/dataplaneapi/operations"
"github.com/haproxytech/dataplaneapi/operations/discovery"
"github.com/haproxytech/dataplaneapi/operations/specification"
"github.com/haproxytech/dataplaneapi/operations/specification_openapiv3"
"github.com/haproxytech/dataplaneapi/operations/version3"
"github.com/haproxytech/dataplaneapi/rate"
"github.com/haproxytech/dataplaneapi/resilient"
socket_runtime "github.com/haproxytech/dataplaneapi/runtime"
Expand Down Expand Up @@ -868,7 +868,7 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
data.ID = service_discovery.NewServiceDiscoveryUUID()
}
if errSD = service_discovery.ValidateConsulData(data, true); errSD != nil {
log.Fatalf("Error validating Consul instance: " + errSD.Error())
log.Fatal("Error validating Consul instance: " + errSD.Error())
}
if errSD = discovery.AddNode("consul", *data.ID, data); errSD != nil {
log.Warning("Error creating consul instance: " + errSD.Error())
Expand All @@ -884,7 +884,7 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
data.ID = service_discovery.NewServiceDiscoveryUUID()
}
if errSD = service_discovery.ValidateAWSData(data, true); errSD != nil {
log.Fatalf("Error validating AWS instance: " + errSD.Error())
log.Fatal("Error validating AWS instance: " + errSD.Error())
}
if errSD = discovery.AddNode("aws", *data.ID, data); errSD != nil {
log.Warning("Error creating AWS instance: " + errSD.Error())
Expand Down Expand Up @@ -917,12 +917,12 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
api.StorageReplaceStorageGeneralFileHandler = &handlers.StorageReplaceStorageGeneralFileHandlerImpl{Client: client, ReloadAgent: ra}

// setup OpenAPI v3 specification handler
api.SpecificationOpenapiv3GetOpenapiv3SpecificationHandler = specification_openapiv3.GetOpenapiv3SpecificationHandlerFunc(func(params specification_openapiv3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder {
api.Version3GetOpenapiv3SpecificationHandler = version3.GetOpenapiv3SpecificationHandlerFunc(func(params version3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder {
v2 := openapi2.T{}
err = v2.UnmarshalJSON(SwaggerJSON)
if err != nil {
e := misc.HandleError(err)
return specification_openapiv3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
return version3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
}

// if host is empty(dynamic hosts), server prop is empty,
Expand All @@ -936,9 +936,9 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
v3, err = openapi2conv.ToV3(&v2)
if err != nil {
e := misc.HandleError(err)
return specification_openapiv3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
return version3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
}
return specification_openapiv3.NewGetOpenapiv3SpecificationOK().WithPayload(v3)
return version3.NewGetOpenapiv3SpecificationOK().WithPayload(v3)
})

// TODO: do we need a ReloadAgent for SPOE
Expand Down Expand Up @@ -1217,10 +1217,10 @@ func handleSignals(ctx context.Context, cancel context.CancelFunc, sigs chan os.
func reloadConfigurationFile(client client_native.HAProxyClient, haproxyOptions dataplaneapi_config.HAProxyConfiguration, users *dataplaneapi_config.Users) {
confClient, err := cn.ConfigureConfigurationClient(haproxyOptions, mWorker)
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}
if err := users.Init(); err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}
log.Info("Rereading Configuration Files")
clientMutex.Lock()
Expand Down
6 changes: 3 additions & 3 deletions discovery/consul_service_discovery_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (c *consulInstance) validateHealthChecks(node *serviceEntry) bool {
}

func (c *consulInstance) validateHealthChecksAny(node *serviceEntry) bool {
if node.Checks == nil || len(node.Checks) == 0 {
if len(node.Checks) == 0 {
return false
}

Expand All @@ -224,7 +224,7 @@ func (c *consulInstance) validateHealthChecksAny(node *serviceEntry) bool {
}

func (c *consulInstance) validateHealthChecksAll(node *serviceEntry) bool {
if node.Checks == nil || len(node.Checks) == 0 {
if len(node.Checks) == 0 {
return false
}

Expand All @@ -237,7 +237,7 @@ func (c *consulInstance) validateHealthChecksAll(node *serviceEntry) bool {
}

func (c *consulInstance) validateHealthChecksMin(node *serviceEntry) bool {
if node.Checks == nil || len(node.Checks) == 0 {
if len(node.Checks) == 0 {
return false
}

Expand Down
1 change: 1 addition & 0 deletions doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e7f56c0

Please sign in to comment.