Skip to content

Commit 78b1e8c

Browse files
authored
Fix golangci linting. (#257)
* Trigger build * Update our action * Try to appease golangci-lint
1 parent a7e0a84 commit 78b1e8c

25 files changed

+99
-94
lines changed

.github/workflows/golangci-lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ jobs:
2121
with:
2222
go-version: "1.24"
2323
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v6
24+
uses: golangci/golangci-lint-action@v8
2525
with:
26-
version: v1.58
26+
version: v2.3.0

.golangci.yaml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
version: "2"
2-
3-
run:
4-
timeout: 5m
5-
62
linters:
7-
disable-all: true
3+
default: none
84
enable:
95
- errcheck
10-
- gosimple
116
- govet
127
- ineffassign
138
- staticcheck
14-
- typecheck
159
- unused
16-
settings:
17-
errcheck:
18-
ignore: ''
19-
10+
issues:
11+
max-issues-per-linter: 0
12+
max-same-issues: 0
13+
fix: true
2014
formatters:
2115
enable:
22-
- goimports
2316
- gofumpt
17+
- goimports
2418
settings:
2519
goimports:
26-
# Put imports beginning with prefix after 3rd-party packages.
27-
# It's a comma-separated list of prefixes.
28-
local-prefixes: github.com/redhatinsights/export-service-go
29-
30-
issues:
31-
max-issues-per-linter: 0
32-
max-same-issues: 0
33-
fix: true
20+
local-prefixes:
21+
- github.com/redhatinsights/export-service-go

cmd/export-service/api_server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
chi "github.com/go-chi/chi/v5"
1515
middleware "github.com/go-chi/chi/v5/middleware"
1616
redoc "github.com/go-openapi/runtime/middleware"
17+
"github.com/labstack/gommon/log"
1718
"github.com/prometheus/client_golang/prometheus/promhttp"
1819
"github.com/redhatinsights/platform-go-middlewares/v2/identity"
1920
"github.com/redhatinsights/platform-go-middlewares/v2/request_id"
@@ -22,6 +23,7 @@ import (
2223
"github.com/confluentinc/confluent-kafka-go/kafka"
2324

2425
s3_manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
26+
2527
"github.com/redhatinsights/export-service-go/config"
2628
"github.com/redhatinsights/export-service-go/db"
2729
"github.com/redhatinsights/export-service-go/exports"
@@ -136,7 +138,10 @@ func setupDocsMiddleware(handler http.Handler) http.Handler {
136138

137139
// Handler function that responds with Hello World
138140
func helloWorld(w http.ResponseWriter, r *http.Request) {
139-
fmt.Fprint(w, "Hello world")
141+
_, err := fmt.Fprint(w, "Hello world")
142+
if err != nil {
143+
log.Panic("failed to respond with Hello world", "error", err)
144+
}
140145
}
141146

142147
// statusOK returns a simple 200 status code

cmd/export-service/expired_export_cleaner.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
)
1010

1111
func startExpiredExportCleaner(cfg *config.ExportConfig, log *zap.SugaredLogger) {
12-
1312
log.Info("Starting expired export cleaner")
1413

1514
dbConnection, err := db.OpenDB(*cfg)

cmd/export-service/main.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ import (
1212
)
1313

1414
func createRootCommand(cfg *config.ExportConfig, log *zap.SugaredLogger) *cobra.Command {
15-
1615
// rootCmd represents the base command when called without any subcommands
17-
var rootCmd = &cobra.Command{
16+
rootCmd := &cobra.Command{
1817
Use: "export-service",
1918
}
2019

21-
var expiredExportCleanerCmd = &cobra.Command{
20+
expiredExportCleanerCmd := &cobra.Command{
2221
Use: "expired_export_cleaner",
2322
Short: "Run the expired export cleaner",
2423
Run: func(cmd *cobra.Command, args []string) {
@@ -28,7 +27,7 @@ func createRootCommand(cfg *config.ExportConfig, log *zap.SugaredLogger) *cobra.
2827

2928
rootCmd.AddCommand(expiredExportCleanerCmd)
3029

31-
var apiServerCmd = &cobra.Command{
30+
apiServerCmd := &cobra.Command{
3231
Use: "api_server",
3332
Short: "Run the api server",
3433
Run: func(cmd *cobra.Command, args []string) {
@@ -38,13 +37,13 @@ func createRootCommand(cfg *config.ExportConfig, log *zap.SugaredLogger) *cobra.
3837

3938
rootCmd.AddCommand(apiServerCmd)
4039

41-
var migrateDbCmd = &cobra.Command{
40+
migrateDbCmd := &cobra.Command{
4241
Use: "migrate_db",
4342
Short: "Run the db migration",
4443
}
4544

4645
// upCmd represents the up command
47-
var upCmd = &cobra.Command{
46+
upCmd := &cobra.Command{
4847
Use: "upgrade",
4948
Short: "Upgrade to a later version",
5049
RunE: func(cmd *cobra.Command, args []string) error {
@@ -54,7 +53,7 @@ func createRootCommand(cfg *config.ExportConfig, log *zap.SugaredLogger) *cobra.
5453
}
5554

5655
// downCmd represents the down command
57-
var downCmd = &cobra.Command{
56+
downCmd := &cobra.Command{
5857
Use: "downgrade",
5958
Short: "Revert to a previous version",
6059
RunE: func(cmd *cobra.Command, args []string) error {

cmd/export-service/migrate_db.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
)
99

1010
func performDbMigration(cfg *config.ExportConfig, log *zap.SugaredLogger, direction string) error {
11-
1211
databaseConn, err := db.OpenPostgresDB(*cfg)
1312
if err != nil {
1413
log.Error("Unable to initialize database connection", "error", err)

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func getRdsCaPath(cfg *clowder.AppConfig) (*string, error) {
285285
}
286286

287287
func buildBaseHttpUrl(tlsEnabled bool, hostname string, port int) string {
288-
var protocol string = "http"
288+
protocol := "http"
289289
if tlsEnabled {
290290
protocol = "https"
291291
}

db/db.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func OpenPostgresDB(cfg config.ExportConfig) (*sql.DB, error) {
2525
}
2626

2727
func buildPostgresDSN(cfg config.ExportConfig) string {
28-
2928
dbcfg := cfg.DBConfig
3029

3130
dsn := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s",

db/migrate_db.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func (lw loggerWrapper) Printf(format string, v ...interface{}) {
2525
}
2626

2727
func PerformDbMigration(databaseConn *sql.DB, log *zap.SugaredLogger, pathToMigrationFiles string, direction string) error {
28-
2928
log.Info("Starting Export Service DB migration")
3029

3130
driver, err := postgres.WithInstance(databaseConn, &postgres.Config{})
@@ -42,12 +41,13 @@ func PerformDbMigration(databaseConn *sql.DB, log *zap.SugaredLogger, pathToMigr
4241

4342
m.Log = loggerWrapper{log}
4443

45-
if direction == "up" {
44+
switch direction {
45+
case "up":
4646
err = m.Up()
47-
} else if direction == "down" {
47+
case "down":
4848
err = m.Steps(-1)
49-
} else {
50-
return errors.New("Invalid operation")
49+
default:
50+
return errors.New("invalid operation")
5151
}
5252

5353
if errors.Is(err, migrate.ErrNoChange) {

exports/exports.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ func (e *Export) ListExports(w http.ResponseWriter, r *http.Request) {
158158
}
159159

160160
exports, count, err := e.DB.APIList(modelUser, &params, page.Offset, page.Limit, page.SortBy, page.Dir)
161-
162161
if err != nil {
163162
logger.Errorw("error while retrieving list from database", "error", err)
164163
InternalServerError(w, err)
@@ -220,7 +219,6 @@ func (e *Export) GetExport(w http.ResponseWriter, r *http.Request) {
220219

221220
// DeleteExport handles DELETE requests to the /exports/{exportUUID} endpoint.
222221
func (e *Export) DeleteExport(w http.ResponseWriter, r *http.Request) {
223-
224222
user := middleware.GetUserIdentity(r.Context())
225223
reqID := request_id.GetReqID(r.Context())
226224

@@ -327,8 +325,8 @@ func DBExportToAPI(payload models.ExportPayload) ExportPayload {
327325
}
328326

329327
if source.SourceError != nil {
330-
newSource.Message = source.SourceError.Message
331-
newSource.Code = source.SourceError.Code
328+
newSource.Message = source.Message
329+
newSource.Code = source.Code
332330
}
333331

334332
apiPayload.Sources = append(apiPayload.Sources, newSource)

0 commit comments

Comments
 (0)