Skip to content

Commit

Permalink
Fix linting added revive config file
Browse files Browse the repository at this point in the history
  • Loading branch information
garaekz committed Jul 28, 2022
1 parent 100f3d4 commit e3705a6
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 130 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ jobs:
go mod verify
go get golang.org/x/tools/cmd/cover
go get github.com/mattn/goveralls
go get golang.org/x/lint/golint
go get github.com/mgechev/revive
- name: Run Revive
run: |
GO111MODULE=off go get github.com/mgechev/revive
$(go env GOPATH)/bin/revive ./... # this is ouput for user
$(go env GOPATH)/bin/revive ./...| xargs -0 -r false # this is for github actions
$(go env GOPATH)/bin/revive -config revive.toml ./... # this is ouput for user
$(go env GOPATH)/bin/revive -config revive.toml ./...| xargs -0 -r false # this is for github actions
- name: Build
run: make build
Expand Down
41 changes: 18 additions & 23 deletions .vscode/targets.log
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ make.exe all --print-data-base --no-builtin-variables --no-builtin-rules --quest
# ALG�N PROP�SITO PARTICULAR.

# Este programa fue construido para i386-pc-mingw32

"grep" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.

El sistema no puede encontrar la ruta especificada.


# Base de datos del Make, mostrada en Wed Jul 27 14:58:47 2022
# Base de datos del Make, mostrada en Wed Jul 27 22:36:45 2022

# Variables

Expand All @@ -40,8 +34,7 @@ SHELL := sh.exe
# entorno
WINDIR = C:\WINDOWS
# entorno
VSCODE_NLS_CO
NFIG = {"locale":"es-419","availableLanguages":{},"_languagePackSupport":true}
VSCODE_NLS_CONFIG = {"locale":"es-419","availableLanguages":{},"_languagePackSupport":true}
# entorno
ONEDRIVE = C:\Users\Gara\OneDrive
# entorno
Expand Down Expand Up @@ -93,7 +86,7 @@ CONFIG_FILE = ./config/local.yml
# autom�tica/o
%F = $(notdir $%)
# entorno
CHROME_CRASHPAD_PIPE_NAME = \\.\pipe\crashpad_10676_XWFJEHNJBKSNRJJG
CHROME_CRASHPAD_PIPE_NAME = \\.\pipe\crashpad_15460_GWVZDVDUABSFQJTQ
# entorno
COMPUTERNAME = GARA
# entorno
Expand Down Expand Up @@ -209,7 +202,7 @@ PROCESSOR_LEVEL = 23
# makefile (de `makefile', l�nea 10):
PID_FILE := './.pid'
# entorno
VSCODE_PID = 10676
VSCODE_PID = 15460
# entorno
USERDOMAIN_ROAMINGPROFILE = GARA
# estad�sticas del conjunto de variables de la tabla de hash:
Expand All @@ -231,7 +224,7 @@ USERDOMAIN_ROAMINGPROFILE = GARA
# C:\Program Files (x86)\Razer Chroma SDK\bin (llave C:/Program Files (x86)/Razer Chroma SDK/bin, mtime 1658930707): 233 archivos, no imposibilidades.
# C:\Windows\System32\WindowsPowerShell\v1.0\ (llave C:/Windows/System32/WindowsPowerShell/v1.0/, mtime 1644603813): 32 archivos, no imposibilidades.
# C:\Windows\System32\Wbem (llave C:/Windows/System32/Wbem, mtime 1657698128): 172 archivos, no imposibilidades.
# . (llave g:/proyectos/goshortv2, mtime 1658651726): 21 archivos, no imposibilidades.
# . (llave g:/proyectos/goshortv2, mtime 1658986341): 19 archivos, no imposibilidades.
# C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common (llave C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common, mtime 1592079710): 10 archivos, no imposibilidades.
# C:\Users\Gara\AppData\Local\Programs\Microsoft VS Code\bin (llave C:/Users/Gara/AppData/Local/Programs/Microsoft VS Code/bin, mtime 1658242550): 4 archivos, no imposibilidades.
# C:\Users\Gara\AppData\Roaming\Python\Python39\Scripts (llave C:/Users/Gara/AppData/Roaming/Python/Python39/Scripts, mtime 1631553126): 25 archivos, no imposibilidades.
Expand Down Expand Up @@ -263,21 +256,16 @@ USERDOMAIN_ROAMINGPROFILE = GARA
# C:\Program Files\dotnet\ (llave C:/Program Files/dotnet/, mtime 1657664583): 13 archivos, no imposibilidades.
# C:\Program Files\Razer Chroma SDK\bin (llave C:/Program Files/Razer Chroma SDK/bin, mtime 1636131824): 5 archivos, no imposibilidades.
# C:\Program Files\PostgreSQL\12\bin: podr�a no estar establecido.
# C:\Users\Gara\go\bin (llave C:/Users/Gara/go/bin, mtime 1658018312): 18 archivos, no imposibilidades.
# C:\Users\Gara\go\bin (llave C:/Users/Gara/go/bin, mtime 1658983262): 19 archivos, no imposibilidades.
# C:\ProgramData\DockerDesktop\version-bin: podr�a no estar establecido.
# C:\Users\Gara\AppData\Local\gitkraken\bin (llave C:/Users/Gara/AppData/Local/gitkraken/bin, mtime 1657405896): 3 archivos, no imposibilidades.
# C:\Program Files\Git\cmd (llave C:/Program Files/Git/cmd, mtime 1620839345): 8 archivos, no imposibilidades.
# C:\Windows\system32 (llave C:/Windows/system32, mtime 1658912261): 3113 archivos, no imposibilidades.
# C:\Windows\system32 (llave C:/Windows/system32, mtime 1658972896): 3113 archivos, no imposibilidades.
# C:\Python38\Lib\site-packages (llave C:/Python38/Lib/site-packages, mtime 1612848763): 85 archivos, no imposibilidades.
# C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR (llave C:/Program Files/NVIDIA Corporation/NVIDIA NvDLISR, mtime 1592079149): 5 archivos, no imposibilidades.
# C:\WINDOWS\system32\config\systemprofile\AppData\Local\
process_begin: CreateProcess(NULL, pwd, ...) failed.
process_begin: CreateProcess(NULL, sed -n s/^dsn:[[:space:]]*\"\(.*\)\"/\1/p ./config/local.yml, ...) failed.
make.exe: *** No hay ninguna regla para construir el objetivo `all'. Alto.
# C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps: podr�a no estar establecido.

Microsoft\WindowsApps: podr�a no estar establecido.

# 4263 archivos, no imposibilidades en 50 directorios.
# 4262 archivos, no imposibilidades en 50 directorios.

# Reglas impl�citas.

Expand Down Expand Up @@ -374,7 +362,7 @@ test:
# No es un objetivo:
makefile:
# La b�squeda de reglas impl�citas ha sido efectuada.
# �ltima modificaci�n 2022-07-19 22:35:30
# �ltima modificaci�n 2022-07-27 22:21:38
# El archivo ha sido actualizado.
# Actualizado con �xito.
# estad�sticas del conjunto de variables de la tabla de hash:
Expand Down Expand Up @@ -528,6 +516,13 @@ run-live:
# strcache size: total = 4096 / max = 4096 / min = 4096 / avg = 4096
# strcache free: total = 4087 / max = 4087 / min = 4087 / avg = 4087

# Se termina la base de datos de Make en Wed Jul 27 14:58:47 2022
# Se termina la base de datos de Make en Wed Jul 27 22:36:45 2022


"grep" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
El sistema no puede encontrar la ruta especificada.
process_begin: CreateProcess(NULL, pwd, ...) failed.
process_begin: CreateProcess(NULL, sed -n s/^dsn:[[:space:]]*\"\(.*\)\"/\1/p ./config/local.yml, ...) failed.
make.exe: *** No hay ninguna regla para construir el objetivo `all'. Alto.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

8 changes: 4 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func main() {
}
}()

dbcontext := dbcontext.New(db)
newDbcontext := dbcontext.New(db)

err = cfg.GetConfigFromDB(dbcontext, logger)
err = cfg.GetConfigFromDB(newDbcontext)
if err != nil {
logger.Errorf("failed to load aditional dynamic configuration: %s", err)
os.Exit(-1)
Expand All @@ -69,7 +69,7 @@ func main() {
address := fmt.Sprintf(":%v", cfg.ServerPort)
hs := &http.Server{
Addr: address,
Handler: buildHandler(logger, dbcontext, cfg),
Handler: buildHandler(logger, newDbcontext, cfg),
}

// start the HTTP server with graceful shutdown
Expand All @@ -82,7 +82,7 @@ func main() {
}

// buildHandler sets up the HTTP routing and builds an HTTP handler.
func buildHandler(logger log.Logger, db *dbcontext.DB, cfg *config.Config) http.Handler {
func buildHandler(logger log.Logger, db *newDbcontext.DB, cfg *config.Config) http.Handler {
router := routing.New()

router.Use(
Expand Down
14 changes: 7 additions & 7 deletions internal/apikey/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type mockRepository struct {
items []entity.APIKey
}

func (m mockRepository) Get(ctx context.Context, key string) (entity.APIKey, error) {
func (m mockRepository) Get(_ context.Context, key string) (entity.APIKey, error) {
if key == "error" || key == "none" {
return entity.APIKey{}, sql.ErrNoRows
}
Expand All @@ -75,7 +75,7 @@ func (m mockRepository) Get(ctx context.Context, key string) (entity.APIKey, err
return entity.APIKey{}, sql.ErrNoRows
}

func (m mockRepository) GetOwned(ctx context.Context, userID string) ([]APIKey, error) {
func (m mockRepository) GetOwned(_ context.Context, userID string) ([]APIKey, error) {
var owned []APIKey
for _, item := range m.items {
if item.UserID == userID {
Expand All @@ -90,11 +90,11 @@ func (m mockRepository) GetOwned(ctx context.Context, userID string) ([]APIKey,
return []APIKey{}, sql.ErrNoRows
}

func (m mockRepository) Count(ctx context.Context) (int, error) {
func (m mockRepository) Count(_ context.Context) (int, error) {
return len(m.items), nil
}

func (m mockRepository) CountByOwner(ctx context.Context, userID string) (int, error) {
func (m mockRepository) CountByOwner(_ context.Context, userID string) (int, error) {
var count int

for _, item := range m.items {
Expand All @@ -106,15 +106,15 @@ func (m mockRepository) CountByOwner(ctx context.Context, userID string) (int, e
return count, nil
}

func (m *mockRepository) Create(ctx context.Context, apiKey entity.APIKey) error {
func (m *mockRepository) Create(_ context.Context, apiKey entity.APIKey) error {
if apiKey.UserID == "error" {
return errCRUD
}
m.items = append(m.items, apiKey)
return nil
}

func (m *mockRepository) Update(ctx context.Context, apiKey entity.APIKey) error {
func (m *mockRepository) Update(_ context.Context, apiKey entity.APIKey) error {
if apiKey.Key == "error" {
return errCRUD
}
Expand All @@ -127,7 +127,7 @@ func (m *mockRepository) Update(ctx context.Context, apiKey entity.APIKey) error
return nil
}

func (m *mockRepository) Delete(ctx context.Context, key string) error {
func (m *mockRepository) Delete(_ context.Context, key string) error {
for i, item := range m.items {
if item.Key == key {
m.items[i] = m.items[len(m.items)-1]
Expand Down
2 changes: 1 addition & 1 deletion internal/auth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func register(service Service, logger log.Logger) routing.Handler {
}
}

func verify(service Service, logger log.Logger) routing.Handler {
func verify(service Service, _ log.Logger) routing.Handler {
return func(c *routing.Context) error {
id := c.Param("id")
token := c.Param("token")
Expand Down
6 changes: 3 additions & 3 deletions internal/auth/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import (

type mockService struct{}

func (m mockService) Login(ctx context.Context, email, password string) (string, error) {
func (mockService) Login(_ context.Context, email, password string) (string, error) {
if email == "[email protected]" && password == "pass" {
return "token-100", nil
}
return "", errors.Unauthorized("")
}

func (m mockService) Register(ctx context.Context, email, password string) error {
func (mockService) Register(_ context.Context, email, password string) error {
if email == "[email protected]" && password == "pass" {
return nil
}
return errors.Unauthorized("")
}

func (m mockService) Verify(ctx context.Context, id, expires string) error {
func (mockService) Verify(_ context.Context, _, _ string) error {
return nil
}

Expand Down
4 changes: 1 addition & 3 deletions internal/auth/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package auth

import (
"context"
"fmt"

"github.com/garaekz/goshort/internal/entity"
"github.com/garaekz/goshort/pkg/dbcontext"
Expand Down Expand Up @@ -71,7 +70,6 @@ func (r repository) Register(ctx context.Context, user entity.User) error {
}

func (r repository) CreateEmailVerification(ctx context.Context, validation entity.EmailVerification) error {
fmt.Printf("%+v", validation)
return r.db.With(ctx).Model(&validation).Insert()
}

Expand All @@ -84,7 +82,7 @@ func (r repository) GetEmailVerification(ctx context.Context, userID, token stri
return validation, nil
}

func (r repository) VerifyEmail(ctx context.Context, validation VerifyRequest) error {
func (r repository) VerifyEmail(_ context.Context, validation VerifyRequest) error {
err := r.db.DB().Transactional(func(tx *dbx.Tx) error {
if _, err := tx.Update("users", dbx.Params{"email_verified": true}, dbx.HashExp{"id": validation.UserID}).Execute(); err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion internal/auth/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@ func TestRepository(t *testing.T) {
})

assert.Nil(t, err)

}
2 changes: 1 addition & 1 deletion internal/auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (s service) authenticate(ctx context.Context, email, password string) Ident
return nil
}

if user.EmailVerified == false {
if !user.EmailVerified {
logger.Infof("User not verified: Authentication failed")
return nil
}
Expand Down
18 changes: 9 additions & 9 deletions internal/auth/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Test_service_Authenticate(t *testing.T) {
pass, _ := bcrypt.GenerateFromPassword([]byte("pass"), bcrypt.MinCost)
repo := &mockRepository{
items: []entity.User{
{ID: "100", Email: "[email protected]", Password: string(pass), CreatedAt: time.Now(), UpdatedAt: time.Now(), IsActive: true},
{ID: "100", Email: "[email protected]", Password: string(pass), CreatedAt: time.Now(), UpdatedAt: time.Now(), IsActive: true, EmailVerified: true},
},
keys: []struct {
Key string
Expand All @@ -44,12 +44,12 @@ func Test_service_Authenticate(t *testing.T) {
assert.NotEmpty(t, token)
}

func Test_service_authenticate(t *testing.T) {
func Test_service_authenticate_function(t *testing.T) {
logger, _ := log.NewForTest()
pass, _ := bcrypt.GenerateFromPassword([]byte("pass"), bcrypt.MinCost)
repo := &mockRepository{
items: []entity.User{
{ID: "100", Email: "[email protected]", Password: string(pass), CreatedAt: time.Now(), UpdatedAt: time.Now(), IsActive: true},
{ID: "100", Email: "[email protected]", Password: string(pass), CreatedAt: time.Now(), UpdatedAt: time.Now(), IsActive: true, EmailVerified: true},
},
keys: []struct {
Key string
Expand Down Expand Up @@ -89,7 +89,7 @@ func Test_service_GenerateJWT(t *testing.T) {
}
}

func (m mockRepository) GetUserByEmail(ctx context.Context, email string) (entity.User, error) {
func (m mockRepository) GetUserByEmail(_ context.Context, email string) (entity.User, error) {
for _, item := range m.items {
if item.Email == email {
return item, nil
Expand All @@ -98,7 +98,7 @@ func (m mockRepository) GetUserByEmail(ctx context.Context, email string) (entit
return entity.User{}, sql.ErrNoRows
}

func (m mockRepository) GetUserByAPIKey(ctx context.Context, apiKey string) (entity.User, error) {
func (m mockRepository) GetUserByAPIKey(_ context.Context, apiKey string) (entity.User, error) {
var userID string
for _, key := range m.keys {
if key.UserID == apiKey {
Expand All @@ -113,22 +113,22 @@ func (m mockRepository) GetUserByAPIKey(ctx context.Context, apiKey string) (ent
return entity.User{}, sql.ErrNoRows
}

func (m mockRepository) Register(ctx context.Context, user entity.User) error {
func (m mockRepository) Register(_ context.Context, user entity.User) error {
if user.ID == "error" {
return errors.Unauthorized("")
}
m.items = append(m.items, user)
return nil
}

func (m mockRepository) CreateEmailVerification(ctx context.Context, verification entity.EmailVerification) error {
func (mockRepository) CreateEmailVerification(_ context.Context, verification entity.EmailVerification) error {
if verification.UserID == "duplicate" {
return errors.BadRequest("The user you're trying to register already exists")
}
return nil
}

func (m mockRepository) GetEmailVerification(ctx context.Context, userID, token string) (entity.EmailVerification, error) {
func (m mockRepository) GetEmailVerification(_ context.Context, userID, _ string) (entity.EmailVerification, error) {
for _, item := range m.items {
if item.ID == userID {
return entity.EmailVerification{UserID: userID}, nil
Expand All @@ -137,6 +137,6 @@ func (m mockRepository) GetEmailVerification(ctx context.Context, userID, token
return entity.EmailVerification{}, sql.ErrNoRows
}

func (m mockRepository) VerifyEmail(ctx context.Context, validation VerifyRequest) error {
func (mockRepository) VerifyEmail(_ context.Context, _ VerifyRequest) error {
return nil
}
Loading

0 comments on commit e3705a6

Please sign in to comment.