diff --git a/.golangci.yaml b/.golangci.yaml index 093be30..0b125c3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,3 +3,11 @@ run: # Exit code when at least one issue was found. # Default: 1 issues-exit-code: 0 + +# All available settings of specific linters. +linters-settings: + errcheck: + # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`. + # Such cases aren't reported by default. + # Default: false + check-blank: false diff --git a/Makefile b/Makefile index c04ac71..e63b089 100644 --- a/Makefile +++ b/Makefile @@ -57,9 +57,14 @@ docker/release: ## Build and release in a docker container. fi compose/up: ## Start docker-compose (args: SVC: name of the service to exclude) - @echo "${GREEN} [*] =============== Docker Compose UP =============== ${RESET}" + @echo "${GREEN} [*] =============== Docker Compose Up =============== ${RESET}" docker compose config --services | grep -v '${SVC}' | xargs docker compose up +compose/up/min: ## Start docker-compose (args: SVC: name of the service to exclude) + @echo "${YELLOW} [*] =============== Docker Compose Up Minimum =============== ${RESET}" + docker compose config --services | grep -v 'clamav\|sandbox\|meta\|orchestrator\|postprocessor\|aggregator\|pe\|ui' \ + | xargs docker compose up + couchbase/start: ## Start Couchbase Server docker container. $(eval COUCHBASE_CONTAINER_STATUS := $(shell docker container inspect -f '{{.State.Status}}' $(COUCHBASE_CONTAINER_NAME))) ifeq ($(COUCHBASE_CONTAINER_STATUS),running) diff --git a/cmd/main.go b/cmd/main.go index 09ba1dd..55ff055 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -103,7 +103,10 @@ func run(logger log.Logger) error { uni := ut.New(en, en) trans, _ := uni.GetTranslator("en") validate := validator.New() - en_translations.RegisterDefaultTranslations(validate, trans) + err = en_translations.RegisterDefaultTranslations(validate, trans) + if err != nil { + return err + } // Create a password securer for auth. sec := password.New(sha256.New()) @@ -132,9 +135,6 @@ func run(logger log.Logger) error { if cfg.SMTP.Server != "" { smtpMailer = mailer.New(cfg.SMTP.Server, cfg.SMTP.Port, cfg.SMTP.User, cfg.SMTP.Password) - if err != nil { - logger.Errorf("failed to connect to smtp server: %v", err) - } emailTemplates, err = tpl.New(*flagTplFiles) if err != nil { return err diff --git a/docker-compose.yaml b/docker-compose.yaml index cd1a630..3e1d62d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,7 +3,7 @@ services: couchbase: - image: couchbase/server:7.2.0 + image: couchbase/server:7.6.1 ports: - "8091:8091" - "8092:8092" @@ -14,7 +14,8 @@ services: - couchbase_data:/opt/couchbase/var nsqlookupd: - image: nsqio/nsq:v1.2.1 + platform: linux/amd64 + image: nsqio/nsq:v1.3.0 command: > /nsqlookupd --log-level=error hostname: nsqlookupd @@ -23,9 +24,11 @@ services: - 4161:4161 nsqd: - image: nsqio/nsq:v1.2.1 + platform: linux/amd64 + image: nsqio/nsq:v1.3.0 command: > - /nsqd --lookupd-tcp-address=nsqlookupd:4160 --broadcast-address=${EXTERNAL_IP} --max-msg-size=1413820683 --log-level=error + /nsqd --lookupd-tcp-address=nsqlookupd:4160 --broadcast-address=${EXTERNAL_IP} --max-msg-size=1413820683 + --log-level=error hostname: nsqd depends_on: - nsqlookupd @@ -34,7 +37,8 @@ services: - 4151:4151 nsqadmin: - image: nsqio/nsq:v1.2.1 + platform: linux/amd64 + image: nsqio/nsq:v1.3.0 command: > /nsqadmin --lookupd-http-address=nsqlookupd:4161 --log-level=error hostname: nsqadmin @@ -44,6 +48,7 @@ services: - 4171:4171 minio: + platform: linux/amd64 image: minio/minio:latest ports: - "9000:9000" @@ -56,6 +61,7 @@ services: command: server /data --console-address ":9001" ui: + platform: linux/amd64 image: saferwall/ui:latest ports: - "3000:3000" @@ -64,69 +70,71 @@ services: PUBLIC_AVATAR_API_URL: https://avatar.saferwall.com/{username} orchestrator: + platform: linux/amd64 image: saferwall/orchestrator:latest environment: - SAFERWALL_DEPLOYMENT_KIND=dev - entrypoint: [ /saferwall/orchestrator-svc, -config, /saferwall/conf/ ] + entrypoint: [/saferwall/orchestrator-svc, -config, /saferwall/conf/] volumes: - - /samples:/samples - - /saferwall:/saferwall/storage + - samples:/samples aggregator: + platform: linux/amd64 image: saferwall/aggregator:latest depends_on: - couchbase environment: - SAFERWALL_DEPLOYMENT_KIND=dev - entrypoint: [ /saferwall/aggregator-svc, -config, /saferwall/conf/ ] + entrypoint: [/saferwall/aggregator-svc, -config, /saferwall/conf/] restart: always postprocessor: + platform: linux/amd64 image: saferwall/postprocessor:latest environment: - SAFERWALL_DEPLOYMENT_KIND=dev - entrypoint: - [ - /saferwall/postprocessor-svc, - -config, - /saferwall/conf/ - ] + entrypoint: [/saferwall/postprocessor-svc, -config, /saferwall/conf/] volumes: - - /samples:/samples + - samples:/samples restart: always pe: + platform: linux/amd64 image: saferwall/pe:latest environment: - SAFERWALL_DEPLOYMENT_KIND=dev - entrypoint: [ /saferwall/pe-svc, -config, /saferwall/conf/ ] + entrypoint: [/saferwall/pe-svc, -config, /saferwall/conf/] volumes: - - /samples:/samples + - samples:/samples meta: + platform: linux/amd64 image: saferwall/gometa:latest environment: - SAFERWALL_DEPLOYMENT_KIND=dev - entrypoint: [ /saferwall/meta-svc, -config, /saferwall/conf/ ] + entrypoint: [/saferwall/meta-svc, -config, /saferwall/conf/] volumes: - - /samples:/samples + - samples:/samples clamav: + platform: linux/amd64 image: saferwall/goclamav:latest environment: - SAFERWALL_DEPLOYMENT_KIND=dev - entrypoint: [ /saferwall/clamav-svc, -config, /saferwall/conf/ ] + entrypoint: [/saferwall/clamav-svc, -config, /saferwall/conf/] volumes: - - /samples:/samples + - samples:/samples sandbox: + platform: linux/amd64 image: saferwall/sandbox:latest environment: - SAFERWALL_DEPLOYMENT_KIND=dev - entrypoint: [ /saferwall/sandbox-svc, -config, /saferwall/conf/ ] + entrypoint: [/saferwall/sandbox-svc, -config, /saferwall/conf/] volumes: - - /samples:/samples + - samples:/samples volumes: + samples: null minio_data: null couchbase_data: null diff --git a/internal/behavior/repostitory.go b/internal/behavior/repostitory.go index 04c7213..a17acee 100644 --- a/internal/behavior/repostitory.go +++ b/internal/behavior/repostitory.go @@ -70,7 +70,7 @@ func (r repository) Get(ctx context.Context, id string, fields []string) ( behaviors := res.([]interface{}) b, _ := json.Marshal(behaviors[0]) - json.Unmarshal(b, &behavior) + _ = json.Unmarshal(b, &behavior) } return behavior, err @@ -118,7 +118,7 @@ func (r repository) Query(ctx context.Context, offset, limit int) ( for _, u := range res.([]interface{}) { behavior := entity.Behavior{} b, _ := json.Marshal(u) - json.Unmarshal(b, &behavior) + _ = json.Unmarshal(b, &behavior) behaviors = append(behaviors, behavior) } return behaviors, nil diff --git a/internal/comment/service.go b/internal/comment/service.go index 4542c2e..91dc6b1 100644 --- a/internal/comment/service.go +++ b/internal/comment/service.go @@ -1,4 +1,4 @@ -// Copyright 2021 Saferwall. All rights reserved. +// Copyright 2018 Saferwall. All rights reserved. // Use of this source code is governed by Apache v2 license // license that can be found in the LICENSE file. @@ -173,7 +173,7 @@ func (s service) Delete(ctx context.Context, id string) (Comment, error) { } // delete corresponsing activity. - if s.actSvc.DeleteWith(ctx, "comment", com.Username, id); err != nil { + if err = s.actSvc.DeleteWith(ctx, "comment", com.Username, id); err != nil { return Comment{}, err } diff --git a/internal/file/repository.go b/internal/file/repository.go index 109f27e..cd2334a 100644 --- a/internal/file/repository.go +++ b/internal/file/repository.go @@ -1,4 +1,4 @@ -// Copyright 2021 Saferwall. All rights reserved. +// Copyright 2018 Saferwall. All rights reserved. // Use of this source code is governed by Apache v2 license // license that can be found in the LICENSE file. @@ -150,7 +150,7 @@ func (r repository) Query(ctx context.Context, offset, limit int, fields []strin for _, u := range res.([]interface{}) { file := entity.File{} b, _ := json.Marshal(u) - json.Unmarshal(b, &file) + _ = json.Unmarshal(b, &file) files = append(files, file) } return files, nil diff --git a/internal/file/service.go b/internal/file/service.go index 528a2cd..ad1e97e 100644 --- a/internal/file/service.go +++ b/internal/file/service.go @@ -405,7 +405,7 @@ func (s service) Unlike(ctx context.Context, sha256 string) error { } // delete corresponding activity. - if s.actSvc.DeleteWith(ctx, "like", user.ID(), + if err = s.actSvc.DeleteWith(ctx, "like", user.ID(), sha256); err != nil { return err } diff --git a/internal/server/server.go b/internal/server/server.go index fbc4459..e557838 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -101,7 +101,7 @@ func BuildHandler(logger log.Logger, db *dbcontext.DB, sec password.Service, // Register a custom fields validator. validate := validator.New() - validate.RegisterValidation("username_or_email", validateUsernameOrEmail) + _ = validate.RegisterValidation("username_or_email", validateUsernameOrEmail) e.Validator = &CustomValidator{validator: validate} // Register a custom binder. diff --git a/internal/template/template.go b/internal/template/template.go index 1b46c43..ee7fed9 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -1,4 +1,4 @@ -// Copyright 2021 Saferwall. All rights reserved. +// Copyright 2018 Saferwall. All rights reserved. // Use of this source code is governed by Apache v2 license // license that can be found in the LICENSE file. @@ -99,6 +99,6 @@ func (er EmailRequest) Execute(templateData interface{}, wr io.Writer) error { if err := er.tpl.Execute(buf, templateData); err != nil { return err } - wr.Write(buf.Bytes()) - return nil + _, err := wr.Write(buf.Bytes()) + return err } diff --git a/internal/user/api.go b/internal/user/api.go index 9d439fc..55b70bb 100644 --- a/internal/user/api.go +++ b/internal/user/api.go @@ -658,13 +658,11 @@ func (r resource) email(c echo.Context) error { err := r.service.UpdateEmail(ctx, req) if err != nil { - if err != nil { - switch err { - case errWrongPassword: - return errors.Forbidden("") - default: - return err - } + switch err { + case errWrongPassword: + return errors.Forbidden("") + default: + return err } } diff --git a/internal/user/repository.go b/internal/user/repository.go index 272ebfc..308161f 100644 --- a/internal/user/repository.go +++ b/internal/user/repository.go @@ -158,7 +158,7 @@ func (r repository) GetByEmail(ctx context.Context, email string) ( user := entity.User{} b, _ := json.Marshal(res.([]interface{})[0]) - json.Unmarshal(b, &user) + _ = json.Unmarshal(b, &user) return user, nil } @@ -182,7 +182,7 @@ func (r repository) Query(ctx context.Context, offset, limit int) ( for _, u := range res.([]interface{}) { user := entity.User{} b, _ := json.Marshal(u) - json.Unmarshal(b, &user) + _ = json.Unmarshal(b, &user) user.Email = "" user.Password = "" users = append(users, user) diff --git a/internal/user/service.go b/internal/user/service.go index 35a6e2b..aea58d2 100644 --- a/internal/user/service.go +++ b/internal/user/service.go @@ -445,7 +445,7 @@ func (s service) UnFollow(ctx context.Context, id string) error { curUser.FollowingCount -= 1 // delete corresponding activity. - if s.actSvc.DeleteWith(ctx, "follow", curUser.Username, + if err = s.actSvc.DeleteWith(ctx, "follow", curUser.Username, targetUser.Username); err != nil { return err } @@ -456,10 +456,10 @@ func (s service) UnFollow(ctx context.Context, id string) error { targetUser.FollowersCount -= 1 } - if s.repo.Update(ctx, curUser.User); err != nil { + if err = s.repo.Update(ctx, curUser.User); err != nil { return err } - if s.repo.Update(ctx, targetUser.User); err != nil { + if err = s.repo.Update(ctx, targetUser.User); err != nil { return err }