Skip to content

Commit

Permalink
Update dependencies and fix linting issues (#437)
Browse files Browse the repository at this point in the history
* Update dependencies
* Fix linter errors reported by revive and perfsprint
  • Loading branch information
mostafa authored Feb 13, 2024
1 parent b4a201f commit 4e9629d
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 103 deletions.
6 changes: 3 additions & 3 deletions api/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func StartHTTPAPI(options *Options) {

mux := http.NewServeMux()
mux.Handle("/", rmux)
mux.HandleFunc("/healthz", func(writer http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/healthz", func(writer http.ResponseWriter, _ *http.Request) {
if liveness(options.Servers) {
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
Expand All @@ -52,7 +52,7 @@ func StartHTTPAPI(options *Options) {
}
})

mux.HandleFunc("/version", func(writer http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/version", func(writer http.ResponseWriter, _ *http.Request) {
writer.WriteHeader(http.StatusOK)
if _, err := writer.Write([]byte(config.Version)); err != nil {
options.Logger.Err(err).Msg("failed to serve version")
Expand All @@ -61,7 +61,7 @@ func StartHTTPAPI(options *Options) {
})

if IsSwaggerEmbedded() {
mux.HandleFunc("/swagger.json", func(writer http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/swagger.json", func(writer http.ResponseWriter, _ *http.Request) {
writer.WriteHeader(http.StatusOK)
data, _ := swaggerUI.ReadFile("v1/api.swagger.json")
if _, err := writer.Write(data); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var configCmd = &cobra.Command{
Use: "config",
Short: "Manage GatewayD global configuration",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
if err := cmd.Help(); err != nil {
log.New(cmd.OutOrStdout(), "", 0).Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/config_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var force bool
var configInitCmd = &cobra.Command{
Use: "init",
Short: "Create or overwrite the GatewayD global config",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
// Enable Sentry.
if enableSentry {
// Initialize Sentry.
Expand Down
2 changes: 1 addition & 1 deletion cmd/config_lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var configLintCmd = &cobra.Command{
Use: "lint",
Short: "Lint the GatewayD global config",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
// Enable Sentry.
if enableSentry {
// Initialize Sentry.
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var pluginCmd = &cobra.Command{
Use: "plugin",
Short: "Manage plugins and their configuration",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
if err := cmd.Help(); err != nil {
log.New(cmd.OutOrStdout(), "", 0).Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var pluginInitCmd = &cobra.Command{
Use: "init",
Short: "Create or overwrite the GatewayD plugins config",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
// Enable Sentry.
if enableSentry {
// Initialize Sentry.
Expand Down
8 changes: 4 additions & 4 deletions cmd/plugin_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Test_pluginInstallCmd(t *testing.T) {

// Clean up.
assert.FileExists(t, "plugins/gatewayd-plugin-cache")
assert.FileExists(t, fmt.Sprintf("%s.bak", pluginTestConfigFile))
assert.FileExists(t, pluginTestConfigFile+BackupFileExt)
assert.NoFileExists(t, "gatewayd-plugin-cache-linux-amd64-v0.2.4.tar.gz")
assert.NoFileExists(t, "checksums.txt")
assert.NoFileExists(t, "plugins/LICENSE")
Expand All @@ -50,7 +50,7 @@ func Test_pluginInstallCmd(t *testing.T) {

require.NoError(t, os.RemoveAll("plugins/"))
require.NoError(t, os.Remove(pluginTestConfigFile))
require.NoError(t, os.Remove(fmt.Sprintf("%s.bak", pluginTestConfigFile)))
require.NoError(t, os.Remove(pluginTestConfigFile+BackupFileExt))
}

func Test_pluginInstallCmdAutomatedNoOverwrite(t *testing.T) {
Expand Down Expand Up @@ -78,12 +78,12 @@ func Test_pluginInstallCmdAutomatedNoOverwrite(t *testing.T) {

// Clean up.
assert.FileExists(t, "plugins/gatewayd-plugin-cache")
assert.FileExists(t, fmt.Sprintf("%s.bak", pluginTestConfigFile))
assert.FileExists(t, pluginTestConfigFile+BackupFileExt)
assert.NoFileExists(t, "plugins/LICENSE")
assert.NoFileExists(t, "plugins/README.md")
assert.NoFileExists(t, "plugins/checksum.txt")
assert.NoFileExists(t, "plugins/gatewayd_plugin.yaml")

require.NoError(t, os.RemoveAll("plugins/"))
require.NoError(t, os.Remove(fmt.Sprintf("%s.bak", pluginTestConfigFile)))
require.NoError(t, os.Remove(pluginTestConfigFile+BackupFileExt))
}
2 changes: 1 addition & 1 deletion cmd/plugin_lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var pluginLintCmd = &cobra.Command{
Use: "lint",
Short: "Lint the GatewayD plugins config",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
// Enable Sentry.
if enableSentry {
// Initialize Sentry.
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var onlyEnabled bool
var pluginListCmd = &cobra.Command{
Use: "list",
Short: "List the GatewayD plugins",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
// Enable Sentry.
if enableSentry {
// Initialize Sentry.
Expand Down
6 changes: 3 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func StopGracefully(
var runCmd = &cobra.Command{
Use: "run",
Short: "Run a GatewayD instance",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
// Enable tracing with OpenTelemetry.
if enableTracing {
// TODO: Make this configurable.
Expand Down Expand Up @@ -427,7 +427,7 @@ var runCmd = &cobra.Command{
}()

mux := http.NewServeMux()
mux.HandleFunc("/", func(responseWriter http.ResponseWriter, request *http.Request) {
mux.HandleFunc("/", func(responseWriter http.ResponseWriter, _ *http.Request) {
// Serve a static page with a link to the metrics endpoint.
if _, err := responseWriter.Write([]byte(fmt.Sprintf(
`<html><head><title>GatewayD Prometheus Metrics Server</title></head><body><a href="%s">Metrics</a></body></html>`,
Expand Down Expand Up @@ -878,7 +878,7 @@ var runCmd = &cobra.Command{
Plugins: []*usage.Plugin{},
}
pluginRegistry.ForEach(
func(identifier sdkPlugin.Identifier, plugin *plugin.Plugin) {
func(identifier sdkPlugin.Identifier, _ *plugin.Plugin) {
report.Plugins = append(report.GetPlugins(), &usage.Plugin{
Name: identifier.Name,
Version: identifier.Version,
Expand Down
3 changes: 1 addition & 2 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
"fmt"
"os"
"sync"
"testing"
Expand Down Expand Up @@ -269,5 +268,5 @@ func Test_runCmdWithCachePlugin(t *testing.T) {
require.NoError(t, os.RemoveAll("plugins/"))
require.NoError(t, os.Remove(globalTestConfigFile))
require.NoError(t, os.Remove(pluginTestConfigFile))
require.NoError(t, os.Remove(fmt.Sprintf("%s.bak", pluginTestConfigFile)))
require.NoError(t, os.Remove(pluginTestConfigFile+BackupFileExt))
}
3 changes: 2 additions & 1 deletion cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
ExecFilePermissions os.FileMode = 0o755
ExecFileMask os.FileMode = 0o111
MaxFileSize int64 = 1024 * 1024 * 100 // 10MB
BackupFileExt string = ".bak"
)

var (
Expand Down Expand Up @@ -737,7 +738,7 @@ func installPlugin(cmd *cobra.Command, pluginURL string) {

// Check if the user wants to take a backup of the plugins configuration file.
if backupConfig {
backupFilename := fmt.Sprintf("%s.bak", pluginConfigFile)
backupFilename := pluginConfigFile + BackupFileExt
if err := os.WriteFile(backupFilename, pluginsConfig, FilePermissions); err != nil {
cmd.Println("There was an error backing up the plugins configuration file: ", err)
}
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
goerrors "errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -462,7 +463,7 @@ func (c *Config) ValidateGlobalConfig(ctx context.Context) {
for _, err := range errors {
log.Println(err)
}
span.RecordError(fmt.Errorf("failed to validate global configuration"))
span.RecordError(goerrors.New("failed to validate global configuration"))
span.End()
log.Fatal("failed to validate global configuration")
}
Expand Down
30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/codingsince1985/checksum v1.3.0
github.com/envoyproxy/protoc-gen-validate v1.0.4
github.com/gatewayd-io/gatewayd-plugin-sdk v0.1.10
github.com/getsentry/sentry-go v0.26.0
github.com/getsentry/sentry-go v0.27.0
github.com/go-co-op/gocron v1.37.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v53 v53.2.0
Expand All @@ -27,13 +27,13 @@ require (
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04
go.opentelemetry.io/otel v1.22.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.22.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.22.0
go.opentelemetry.io/otel/sdk v1.22.0
go.opentelemetry.io/otel/trace v1.22.0
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe
go.opentelemetry.io/otel v1.23.1
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.1
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.23.1
go.opentelemetry.io/otel/sdk v1.23.1
go.opentelemetry.io/otel/trace v1.23.1
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3
google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014
google.golang.org/grpc v1.61.0
google.golang.org/protobuf v1.32.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
Expand Down Expand Up @@ -72,15 +72,15 @@ require (
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto v0.0.0-20240205150955-31a09d347014 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 // indirect
)
Loading

0 comments on commit 4e9629d

Please sign in to comment.