diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index aa56780..512fe8a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,8 +16,16 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.22' + go-version: '1.26' + - name: Test if go.mod and go.sum are up to date + run: | + go mod tidy + git diff --exit-code + - name: Check if conformant to go fix + run: | + go fix ./... + git diff --exit-code - name: Run linters run: go tool golangci-lint run diff --git a/docker/admin/Dockerfile b/docker/admin/Dockerfile index 2a17eae..715dd7d 100644 --- a/docker/admin/Dockerfile +++ b/docker/admin/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.24-alpine as build +FROM golang:1.26-alpine as build ENV GO111MODULE=on \ CGO_ENABLED=0 \ diff --git a/docker/api/Dockerfile b/docker/api/Dockerfile index 208ea5a..24643b4 100644 --- a/docker/api/Dockerfile +++ b/docker/api/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.24-alpine as build +FROM golang:1.26-alpine as build ENV GO111MODULE=on \ CGO_ENABLED=0 \ diff --git a/docker/websocket/Dockerfile b/docker/websocket/Dockerfile index 0720a11..912ce41 100644 --- a/docker/websocket/Dockerfile +++ b/docker/websocket/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.24-alpine as build +FROM golang:1.26-alpine as build ENV GO111MODULE=on \ CGO_ENABLED=0 \ diff --git a/e2e-tests/browser_extension/browser_extension_test.go b/e2e-tests/browser_extension/browser_extension_test.go index 102df05..5431355 100644 --- a/e2e-tests/browser_extension/browser_extension_test.go +++ b/e2e-tests/browser_extension/browser_extension_test.go @@ -91,10 +91,10 @@ func createBrowserExtension(t *testing.T, name string) *http.Response { pubKey := crypto.PublicKeyToBase64(keyPair.PublicKey) - payload := []byte(fmt.Sprintf( + payload := fmt.Appendf(nil, `{"name":"%s","browser_name":"go-browser","browser_version":"0.1","public_key":"%s"}`, name, - pubKey)) + pubKey) return e2e_tests.DoAPIRequest(t, "/browser_extensions", http.MethodPost, payload, nil) } diff --git a/e2e-tests/helpers.go b/e2e-tests/helpers.go index fdaa9b4..eecc84a 100644 --- a/e2e-tests/helpers.go +++ b/e2e-tests/helpers.go @@ -14,7 +14,7 @@ func CreateDevice(t *testing.T, name, fcmToken string) (*DeviceResponse, string) keyPair := crypto.GenerateKeyPair(2048) devicePubKey := crypto.PublicKeyToBase64(keyPair.PublicKey) - payload := []byte(fmt.Sprintf(`{"name":"%s","platform":"android","fcm_token":"%s"}`, name, fcmToken)) + payload := fmt.Appendf(nil, `{"name":"%s","platform":"android","fcm_token":"%s"}`, name, fcmToken) device := new(DeviceResponse) @@ -30,10 +30,10 @@ func CreateBrowserExtension(t *testing.T, name string) *BrowserExtensionResponse pubKey := crypto.PublicKeyToBase64(keyPair.PublicKey) - payload := []byte( - fmt.Sprintf( + payload := + fmt.Appendf(nil, `{"name":"%s","browser_name":"go-browser","browser_version":"0.1","public_key":"%s"}`, - name, pubKey)) + name, pubKey) browserExt := new(BrowserExtensionResponse) @@ -45,9 +45,9 @@ func CreateBrowserExtension(t *testing.T, name string) *BrowserExtensionResponse func CreateBrowserExtensionWithPublicKey(t *testing.T, name, publicKey string) *BrowserExtensionResponse { t.Helper() - payload := []byte( - fmt.Sprintf(`{"name":"%s","browser_name":"go-browser","browser_version":"0.1","public_key":"%s"}`, - name, publicKey)) + payload := + fmt.Appendf(nil, `{"name":"%s","browser_name":"go-browser","browser_version":"0.1","public_key":"%s"}`, + name, publicKey) browserExt := new(BrowserExtensionResponse) @@ -100,7 +100,7 @@ func Request2FaToken(t *testing.T, domain, extensionId string) *AuthTokenRequest var response *AuthTokenRequestResponse - payload := []byte(fmt.Sprintf(`{"domain":"%s"}`, domain)) + payload := fmt.Appendf(nil, `{"domain":"%s"}`, domain) DoAPISuccessPost(t, "browser_extensions/"+extensionId+"/commands/request_2fa_token", payload, &response) diff --git a/e2e-tests/http.go b/e2e-tests/http.go index 2928880..4dce153 100644 --- a/e2e-tests/http.go +++ b/e2e-tests/http.go @@ -30,13 +30,13 @@ func (a *BasicAuth) Header() string { return "Basic " + base64.StdEncoding.EncodeToString([]byte(base)) } -func DoAPISuccessPost(t *testing.T, uri string, payload []byte, resp interface{}) { +func DoAPISuccessPost(t *testing.T, uri string, payload []byte, resp any) { t.Helper() response := doRequest(t, apiRawURL, uri, http.MethodPost, payload, resp) require.Equal(t, http.StatusOK, response.StatusCode) } -func DoAdminAPISuccessPost(t *testing.T, uri string, payload []byte, resp interface{}) { +func DoAdminAPISuccessPost(t *testing.T, uri string, payload []byte, resp any) { t.Helper() response := doRequest(t, adminRawURL, uri, http.MethodPost, payload, resp) bb, err := io.ReadAll(response.Body) @@ -45,29 +45,29 @@ func DoAdminAPISuccessPost(t *testing.T, uri string, payload []byte, resp interf require.Equal(t, http.StatusOK, response.StatusCode, "invalid status code, response payload is: %q", string(bb)) } -func DoAdminPostAndAssertCode(t *testing.T, expCode int, uri string, payload []byte, resp interface{}) { +func DoAdminPostAndAssertCode(t *testing.T, expCode int, uri string, payload []byte, resp any) { t.Helper() response := doRequest(t, adminRawURL, uri, http.MethodPost, payload, resp) require.Equal(t, expCode, response.StatusCode) } -func DoAPIPostAndAssertCode(t *testing.T, expCode int, uri string, payload []byte, resp interface{}) { +func DoAPIPostAndAssertCode(t *testing.T, expCode int, uri string, payload []byte, resp any) { t.Helper() response := doRequest(t, apiRawURL, uri, http.MethodPost, payload, resp) require.Equal(t, expCode, response.StatusCode) } -func DoAPIRequest(t *testing.T, uri, method string, payload []byte, resp interface{}) *http.Response { +func DoAPIRequest(t *testing.T, uri, method string, payload []byte, resp any) *http.Response { t.Helper() return doRequest(t, apiRawURL, uri, method, payload, resp) } -func DoAdminRequest(t *testing.T, uri, method string, payload []byte, resp interface{}) *http.Response { +func DoAdminRequest(t *testing.T, uri, method string, payload []byte, resp any) *http.Response { t.Helper() return doRequest(t, apiRawURL, uri, method, payload, resp) } -func DoAdminSuccessPut(t *testing.T, uri string, payload []byte, resp interface{}) { +func DoAdminSuccessPut(t *testing.T, uri string, payload []byte, resp any) { t.Helper() response := doRequest(t, adminRawURL, uri, http.MethodPut, payload, resp) bb, err := io.ReadAll(response.Body) @@ -76,26 +76,26 @@ func DoAdminSuccessPut(t *testing.T, uri string, payload []byte, resp interface{ require.Equal(t, http.StatusOK, response.StatusCode, "invalid status code, response payload is: %q", string(bb)) } -func DoAPISuccessPut(t *testing.T, uri string, payload []byte, resp interface{}) { +func DoAPISuccessPut(t *testing.T, uri string, payload []byte, resp any) { t.Helper() response := doRequest(t, apiRawURL, uri, http.MethodPut, payload, resp) require.Equal(t, http.StatusOK, response.StatusCode) } -func DoAPISuccessGet(t *testing.T, uri string, resp interface{}) { +func DoAPISuccessGet(t *testing.T, uri string, resp any) { t.Helper() response := doRequest(t, apiRawURL, uri, http.MethodGet, nil /*payload*/, resp) require.Equal(t, http.StatusOK, response.StatusCode) } -func DoAPIGet(t *testing.T, uri string, resp interface{}) *http.Response { +func DoAPIGet(t *testing.T, uri string, resp any) *http.Response { t.Helper() return doRequest(t, apiRawURL, uri, http.MethodGet, nil /*payload*/, resp) } -func DoAdminSuccessGet(t *testing.T, uri string, resp interface{}) { +func DoAdminSuccessGet(t *testing.T, uri string, resp any) { t.Helper() response := doRequest(t, adminRawURL, uri, http.MethodGet, nil /*payload*/, resp) require.Equal(t, http.StatusOK, response.StatusCode) @@ -113,7 +113,7 @@ func DoAPISuccessDelete(t *testing.T, uri string) { require.Equal(t, http.StatusOK, response.StatusCode) } -func doRequest(t *testing.T, base, uri, method string, payload []byte, resp interface{}) *http.Response { +func doRequest(t *testing.T, base, uri, method string, payload []byte, resp any) *http.Response { t.Helper() baseURL, err := url.Parse(base) require.NoError(t, err) diff --git a/e2e-tests/icons/icons_requests_test.go b/e2e-tests/icons/icons_requests_test.go index 1c4e42b..7d32e3e 100644 --- a/e2e-tests/icons/icons_requests_test.go +++ b/e2e-tests/icons/icons_requests_test.go @@ -3,7 +3,7 @@ package tests import ( "encoding/base64" "encoding/json" - "io/ioutil" + "os" "testing" "github.com/jaswdr/faker" @@ -38,7 +38,7 @@ func (s *IconsRequestsTestSuite) TestCreateIconRequest() { func (s *IconsRequestsTestSuite) TestCreateIconRequestWithNotAllowedIconDimensions() { img := faker.New().Image().Image(120, 60) - pngImg, err := ioutil.ReadFile(img.Name()) + pngImg, err := os.ReadFile(img.Name()) if err != nil { s.T().Error(err) @@ -157,7 +157,7 @@ func createIconRequest(t *testing.T, serviceName string) *queries.IconRequestPre img := faker.New().Image().Image(120, 120) - pngImg, err := ioutil.ReadFile(img.Name()) + pngImg, err := os.ReadFile(img.Name()) if err != nil { t.Error(err) diff --git a/e2e-tests/icons/icons_test.go b/e2e-tests/icons/icons_test.go index b0b48e8..30a6ae6 100644 --- a/e2e-tests/icons/icons_test.go +++ b/e2e-tests/icons/icons_test.go @@ -2,7 +2,8 @@ package tests import ( "encoding/base64" - "io/ioutil" + "os" + "testing" "github.com/jaswdr/faker" @@ -16,7 +17,7 @@ func createIcon(t *testing.T) *query.IconPresenter { t.Helper() img := faker.New().Image().Image(120, 120) - pngImg, err := ioutil.ReadFile(img.Name()) + pngImg, err := os.ReadFile(img.Name()) if err != nil { t.Error(err) diff --git a/e2e-tests/icons/web_services_dump_test.go b/e2e-tests/icons/web_services_dump_test.go index 89a972d..fda1a2e 100644 --- a/e2e-tests/icons/web_services_dump_test.go +++ b/e2e-tests/icons/web_services_dump_test.go @@ -38,7 +38,7 @@ func createWebService(t *testing.T) *webServiceResponse { iconsCollection := createIconsCollection(t) id := fmt.Sprintf("service-%d", rand.Int()) // nolint:gosec // only for tests - payload := []byte(fmt.Sprintf(` + payload := fmt.Appendf(nil, ` { "name":"%s", "description":"another", @@ -46,7 +46,7 @@ func createWebService(t *testing.T) *webServiceResponse { "tags":["shitbook"], "icons_collections":["%s"] } - `, id, iconsCollection.Id)) + `, id, iconsCollection.Id) var webService *webServiceResponse diff --git a/e2e-tests/mobile/mobile_device_extension_test.go b/e2e-tests/mobile/mobile_device_extension_test.go index f7c3fc2..a2dcb9d 100644 --- a/e2e-tests/mobile/mobile_device_extension_test.go +++ b/e2e-tests/mobile/mobile_device_extension_test.go @@ -99,10 +99,10 @@ func (s *MobileDeviceExtensionTestSuite) TestExtensionHasAlreadyBeenConnected() device, devicePubKey := e2e_tests.CreateDevice(s.T(), "go-test-device", "some-device-id") e2e_tests.PairDeviceWithBrowserExtension(s.T(), devicePubKey, extension, device) - payload := []byte(fmt.Sprintf(`{"extension_id":"%s","device_name":"%s","device_public_key":"%s"}`, + payload := fmt.Appendf(nil, `{"extension_id":"%s","device_name":"%s","device_public_key":"%s"}`, extension.Id, device.Name, - devicePubKey)) + devicePubKey) e2e_tests.DoAPIPostAndAssertCode(s.T(), 409, diff --git a/e2e-tests/mobile/mobile_device_test.go b/e2e-tests/mobile/mobile_device_test.go index ff14655..fb4d3f0 100644 --- a/e2e-tests/mobile/mobile_device_test.go +++ b/e2e-tests/mobile/mobile_device_test.go @@ -49,6 +49,6 @@ func (s *MobileDeviceTestSuite) TestCreateMobileDevice() { func createDevice(t *testing.T, name, fcmToken string) *http.Response { t.Helper() - payload := []byte(fmt.Sprintf(`{"name":"%s","platform":"android","fcm_token":"%s"}`, name, fcmToken)) + payload := fmt.Appendf(nil, `{"name":"%s","platform":"android","fcm_token":"%s"}`, name, fcmToken) return e2e_tests.DoAPIRequest(t, "mobile/devices", http.MethodPost, payload, nil) } diff --git a/e2e-tests/mobile/mobile_security_test.go b/e2e-tests/mobile/mobile_security_test.go index ccb546b..818b38d 100644 --- a/e2e-tests/mobile/mobile_security_test.go +++ b/e2e-tests/mobile/mobile_security_test.go @@ -20,7 +20,7 @@ func Test_MobileApiBandwidthAbuse(t *testing.T) { eg := errgroup.Group{} eg.SetLimit(noOfWorkers) - for i := 0; i < noOfRequest; i++ { + for range noOfRequest { eg.Go(func() error { resp := e2e_tests.DoAPIGet(t, "/mobile/devices/"+someId.String()+"/browser_extensions", nil) @@ -58,7 +58,7 @@ func Test_BrowserExtensionApiBandwidthAbuse(t *testing.T) { eg := errgroup.Group{} eg.SetLimit(noOfWorkers) - for i := 0; i < noOfRequest; i++ { + for range noOfRequest { eg.Go(func() error { resp := e2e_tests.DoAPIGet(t, "/browser_extensions/"+someId.String(), nil) diff --git a/e2e-tests/support/mobile_debug_logs_test.go b/e2e-tests/support/mobile_debug_logs_test.go index cc3d109..84f1bb5 100644 --- a/e2e-tests/support/mobile_debug_logs_test.go +++ b/e2e-tests/support/mobile_debug_logs_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "mime/multipart" "net/http" "strings" @@ -74,10 +73,10 @@ func (s *DebugLogsAuditTestSuite) TestFulfillDebugLogsAuditClaim() { s.Require().NoError(err) s.Equal(200, response.StatusCode) - reqB, _ := ioutil.ReadAll(body) + reqB, _ := io.ReadAll(body) s.T().Log(string(reqB)) - rawBody, _ := ioutil.ReadAll(response.Body) + rawBody, _ := io.ReadAll(response.Body) s.T().Log(string(rawBody)) } diff --git a/go.mod b/go.mod index b45dba9..8742007 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/twofas/2fas-server -go 1.24.0 +go 1.26.0 require ( firebase.google.com/go/v4 v4.15.2 diff --git a/internal/api/app.go b/internal/api/app.go index 7ff545e..007c105 100644 --- a/internal/api/app.go +++ b/internal/api/app.go @@ -58,7 +58,7 @@ func NewApplication(applicationName string, config config.Configuration) (*Appli pushClient = push.NewFakePushClient() } else { sess, err := session.NewSession(&aws.Config{ - Region: aws.String(config.Aws.Region), + Region: new(config.Aws.Region), }) if err != nil { return nil, fmt.Errorf("failed to create aws session: %w", err) diff --git a/internal/api/browser_extension/app/command/request_2fa_token.go b/internal/api/browser_extension/app/command/request_2fa_token.go index c090310..9a74f6e 100644 --- a/internal/api/browser_extension/app/command/request_2fa_token.go +++ b/internal/api/browser_extension/app/command/request_2fa_token.go @@ -84,7 +84,7 @@ func (h *Request2FaTokenHandler) Handle( return nil, err } - data := map[string]interface{}{ + data := map[string]any{ "extension_id": extId.String(), "request_id": cmd.Id, "domain": cmd.Domain, @@ -113,7 +113,7 @@ func (h *Request2FaTokenHandler) sendPush( ctx context.Context, log logging.FieldLogger, device *domain.ExtensionDevice, - data map[string]interface{}) PushNotificationStatus { + data map[string]any) PushNotificationStatus { if device.FcmToken == "" { log.Info("Cannot send push notification, missing FCM token") return PushNotificationStatusNoFCM @@ -157,7 +157,7 @@ func (h *Request2FaTokenHandler) findPairedDevices( func (h *Request2FaTokenHandler) sendNotification(ctx context.Context, device *domain.ExtensionDevice, - data map[string]interface{}) error { + data map[string]any) error { var notification *messaging.Message switch device.Platform { @@ -176,7 +176,7 @@ func (h *Request2FaTokenHandler) sendNotification(ctx context.Context, ) } -func createPushNotificationForIos(token string, data map[string]interface{}) *messaging.Message { +func createPushNotificationForIos(token string, data map[string]any) *messaging.Message { ttl := time.Now().Add(tokenPushNotificationTtl) return &messaging.Message{ @@ -200,7 +200,7 @@ func createPushNotificationForIos(token string, data map[string]interface{}) *me } } -func createPushNotificationForAndroid(token string, data map[string]interface{}) *messaging.Message { +func createPushNotificationForAndroid(token string, data map[string]any) *messaging.Message { androidData := make(map[string]string, len(data)) for key, value := range data { diff --git a/internal/api/health/ports/http.go b/internal/api/health/ports/http.go index 66db45f..8da6927 100644 --- a/internal/api/health/ports/http.go +++ b/internal/api/health/ports/http.go @@ -114,7 +114,7 @@ func (r *RoutesHandler) RedisInfo(c *gin.Context) { func (r *RoutesHandler) GetApplicationConfiguration(c *gin.Context) { sess, err := session.NewSession(&aws.Config{ - Region: aws.String(config.Config.Aws.Region), + Region: new(config.Config.Aws.Region), }) if err != nil { // This is an internal endpoint, so we can return the error as is. diff --git a/internal/api/support/app/command/create_debug_log_audit.go b/internal/api/support/app/command/create_debug_log_audit.go index 3fcc9c4..e8f8f67 100644 --- a/internal/api/support/app/command/create_debug_log_audit.go +++ b/internal/api/support/app/command/create_debug_log_audit.go @@ -3,7 +3,8 @@ package command import ( "bytes" "errors" - "io/ioutil" + "io" + "mime/multipart" "path/filepath" @@ -58,7 +59,7 @@ func (h *CreateDebugLogsAuditHandler) Handle(command *CreateDebugLogsAudit) erro return err } - file, _ := ioutil.ReadAll(logsFile) + file, _ := io.ReadAll(logsFile) logsFileReader := bytes.NewReader(file) diff --git a/internal/common/logging/logger.go b/internal/common/logging/logger.go index b91521e..2858ffb 100644 --- a/internal/common/logging/logger.go +++ b/internal/common/logging/logger.go @@ -66,35 +66,35 @@ func WithField(key string, value any) FieldLogger { return log.WithField(key, value) } -func Info(args ...interface{}) { +func Info(args ...any) { log.Info(args...) } -func Infof(format string, args ...interface{}) { +func Infof(format string, args ...any) { log.Infof(format, args...) } -func Error(args ...interface{}) { +func Error(args ...any) { log.Error(args...) } -func Errorf(format string, args ...interface{}) { +func Errorf(format string, args ...any) { log.Errorf(format, args...) } -func Warning(args ...interface{}) { +func Warning(args ...any) { log.Warning(args...) } -func Fatal(args ...interface{}) { +func Fatal(args ...any) { log.Fatal(args...) } -func Fatalf(format string, args ...interface{}) { +func Fatalf(format string, args ...any) { log.Fatalf(format, args...) } -func LogCommand(command interface{}) { +func LogCommand(command any) { context, err := json.Marshal(command) if err != nil { log.Errorf("Failed to marshal command for logging: %v", err) @@ -116,7 +116,7 @@ func LogCommand(command interface{}) { }).Info("Start command " + commandName) } -func LogCommandFailed(command interface{}, err error) { +func LogCommandFailed(command any, err error) { commandName := reflect.TypeOf(command).Elem().Name() log. WithFields(logrus.Fields{ diff --git a/internal/common/push/client.go b/internal/common/push/client.go index 16f79a0..5e84807 100644 --- a/internal/common/push/client.go +++ b/internal/common/push/client.go @@ -4,7 +4,8 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" + "time" firebase "firebase.google.com/go/v4" @@ -24,7 +25,7 @@ type FcmPushClient struct { } func NewFcmPushClient(config *domain.FcmPushConfig) *FcmPushClient { - fileContent, err := ioutil.ReadAll(config.FcmApiServiceAccountFile) + fileContent, err := io.ReadAll(config.FcmApiServiceAccountFile) if err != nil { logging.Fatal(err) diff --git a/internal/common/recovery/gin.go b/internal/common/recovery/gin.go index 863be2e..22d978d 100644 --- a/internal/common/recovery/gin.go +++ b/internal/common/recovery/gin.go @@ -3,7 +3,8 @@ package recovery import ( "bytes" "fmt" - "io/ioutil" + "os" + "runtime" "github.com/gin-gonic/gin" @@ -42,7 +43,7 @@ func stack(skip int) []byte { // Print this much at least. If we can't find the source, it won't show. fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc) if file != lastFile { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err != nil { continue } diff --git a/internal/common/storage/fs.go b/internal/common/storage/fs.go index ef35ba2..0d1f43e 100644 --- a/internal/common/storage/fs.go +++ b/internal/common/storage/fs.go @@ -3,7 +3,7 @@ package storage import ( "fmt" "io" - "io/ioutil" + "os" "path/filepath" "strings" @@ -45,7 +45,7 @@ func (fs *TmpFileSystem) Save(path string, data io.Reader) (location string, err return "", err } - content, err := ioutil.ReadAll(data) + content, err := io.ReadAll(data) if err != nil { return "", err diff --git a/internal/common/storage/s3.go b/internal/common/storage/s3.go index e7b50b5..0cb15fb 100644 --- a/internal/common/storage/s3.go +++ b/internal/common/storage/s3.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" @@ -36,8 +35,8 @@ func (s *S3) Get(path string) (file *os.File, err error) { } _, err = downloader.Download(f, &s3.GetObjectInput{ - Bucket: aws.String(directory), - Key: aws.String(name), + Bucket: new(directory), + Key: new(name), }) if err != nil { return nil, fmt.Errorf("failed to download the object from s3: %w", err) @@ -53,8 +52,8 @@ func (s *S3) Save(path string, data io.Reader) (location string, err error) { uploader := s3manager.NewUploader(s.sess) result, err := uploader.Upload(&s3manager.UploadInput{ - Bucket: aws.String(directory), - Key: aws.String(name), + Bucket: new(directory), + Key: new(name), Body: data, }) @@ -90,8 +89,8 @@ func (s *S3) Move(oldPath, newPath string) (location string, err error) { } _, err = svc.DeleteObject(&s3.DeleteObjectInput{ - Bucket: aws.String(sourceDirectory), - Key: aws.String(sourceName)}, + Bucket: new(sourceDirectory), + Key: new(sourceName)}, ) if err != nil { diff --git a/internal/common/websocket/gorilla_websocket_client.go b/internal/common/websocket/gorilla_websocket_client.go index e7903b5..21c3322 100644 --- a/internal/common/websocket/gorilla_websocket_client.go +++ b/internal/common/websocket/gorilla_websocket_client.go @@ -23,7 +23,7 @@ func NewWebsocketApiClient(websocketApiUrl string) *WebsocketApiClient { } } -func (ws *WebsocketApiClient) SendMessage(uri string, message interface{}) error { +func (ws *WebsocketApiClient) SendMessage(uri string, message any) error { u, err := url.Parse(ws.wsAddr) if err != nil { return fmt.Errorf("failed to parse %q: %w", ws.wsAddr, err) diff --git a/internal/websocket/common/client.go b/internal/websocket/common/client.go index 2c150df..f86cb30 100644 --- a/internal/websocket/common/client.go +++ b/internal/websocket/common/client.go @@ -125,7 +125,7 @@ func (c *Client) writePump() { // Add queued chat messages to the current websocket message. n := len(c.send) - for i := 0; i < n; i++ { + for range n { if _, err := w.Write(newline); err != nil { return } diff --git a/internal/websocket/common/hub_pool_test.go b/internal/websocket/common/hub_pool_test.go index f1dba3a..deb51c4 100644 --- a/internal/websocket/common/hub_pool_test.go +++ b/internal/websocket/common/hub_pool_test.go @@ -63,21 +63,21 @@ func TestCreateRemoveConcurrently(t *testing.T) { // wait for it to finish. wg.Add(channelsNo * clientsPerChannel) - for i := 0; i < channelsNo; i++ { + for i := range channelsNo { channelID := fmt.Sprintf("channel-%d", i) c, h := hp.registerClient(channelID, &websocket.Conn{}) hubs.Store(h, struct{}{}) go fakeReadPump(c.send, &wg) go func() { - for i := 0; i < messagesSentToEachHub; i++ { + for range messagesSentToEachHub { h.broadcastMsg([]byte("test")) } }() go func() { defer wg.Done() - for j := 0; j < clientsPerChannel; j++ { + for range clientsPerChannel { c, h := hp.registerClient(channelID, &websocket.Conn{}) go fakeReadPump(c.send, &wg)