From eef04f1b947dacf818b97ba4c663939fda4e3c3e Mon Sep 17 00:00:00 2001 From: oleksandrkhmil Date: Fri, 10 Jan 2025 17:04:10 +0200 Subject: [PATCH 1/2] feat: change pkg name format --- cmd/service/main.go | 7 ++++--- go.mod | 2 +- internal/app.go | 5 +++-- internal/db/db.go | 3 ++- internal/handler/auth_handler.go | 7 ++++--- internal/handler/auth_handler_mock_test.go | 2 +- internal/handler/auth_handler_test.go | 7 ++++--- internal/handler/post_handler.go | 9 +++++---- internal/provider/jwt_auth.go | 9 +++++---- internal/repository/mocks/user_repository_mock.go | 5 +++-- internal/repository/mocks/users_repository_mockery.go | 2 +- internal/repository/post_repository.go | 2 +- internal/repository/user_repository.go | 3 ++- internal/repository/user_repository_test.go | 2 +- internal/response/post_responses.go | 2 +- internal/server/repository/post_repository.go | 2 +- internal/server/repository/user_repository.go | 3 ++- internal/server/routes.go | 10 +++++----- internal/server/server.go | 4 ++-- internal/server/service/post_service.go | 2 +- internal/service/errors.go | 2 +- internal/service/post_service.go | 5 +++-- internal/service/user_service.go | 5 +++-- internal/service/user_service_mock_test.go | 2 +- internal/service/user_service_test.go | 8 ++++---- 25 files changed, 61 insertions(+), 49 deletions(-) diff --git a/cmd/service/main.go b/cmd/service/main.go index 2a7f958..2b798a3 100644 --- a/cmd/service/main.go +++ b/cmd/service/main.go @@ -1,13 +1,14 @@ package main import ( - "basic_server/docs" - application "basic_server/internal" - "basic_server/internal/config" "fmt" "log" "os" + "github.com/nix-united/golang-gin-boilerplate/docs" + application "github.com/nix-united/golang-gin-boilerplate/internal" + "github.com/nix-united/golang-gin-boilerplate/internal/config" + "github.com/joho/godotenv" ) diff --git a/go.mod b/go.mod index 1ddff5b..8411c6b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module basic_server +module github.com/nix-united/golang-gin-boilerplate go 1.23.2 diff --git a/internal/app.go b/internal/app.go index 91c22a9..bd04959 100644 --- a/internal/app.go +++ b/internal/app.go @@ -1,9 +1,10 @@ package application import ( - "basic_server/internal/config" - "basic_server/internal/server" "log" + + "github.com/nix-united/golang-gin-boilerplate/internal/config" + "github.com/nix-united/golang-gin-boilerplate/internal/server" ) func Start(cfg *config.Config) { diff --git a/internal/db/db.go b/internal/db/db.go index ad82978..fe4da6a 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -1,11 +1,12 @@ package db import ( - "basic_server/internal/config" "database/sql" "fmt" "time" + "github.com/nix-united/golang-gin-boilerplate/internal/config" + "gorm.io/driver/mysql" "gorm.io/gorm" ) diff --git a/internal/handler/auth_handler.go b/internal/handler/auth_handler.go index 15c2f29..948df3c 100644 --- a/internal/handler/auth_handler.go +++ b/internal/handler/auth_handler.go @@ -1,12 +1,13 @@ package handler import ( - operror "basic_server/internal/errors" - "basic_server/internal/request" - "basic_server/internal/response" "errors" "net/http" + operror "github.com/nix-united/golang-gin-boilerplate/internal/errors" + "github.com/nix-united/golang-gin-boilerplate/internal/request" + "github.com/nix-united/golang-gin-boilerplate/internal/response" + "github.com/gin-gonic/gin" ) diff --git a/internal/handler/auth_handler_mock_test.go b/internal/handler/auth_handler_mock_test.go index 2cbf6f7..6c83fad 100644 --- a/internal/handler/auth_handler_mock_test.go +++ b/internal/handler/auth_handler_mock_test.go @@ -10,7 +10,7 @@ package handler_test import ( - request "basic_server/internal/request" + request "github.com/nix-united/golang-gin-boilerplate/internal/request" reflect "reflect" gomock "go.uber.org/mock/gomock" diff --git a/internal/handler/auth_handler_test.go b/internal/handler/auth_handler_test.go index 9d8129b..ccd5579 100644 --- a/internal/handler/auth_handler_test.go +++ b/internal/handler/auth_handler_test.go @@ -1,9 +1,6 @@ package handler_test import ( - "basic_server/internal/handler" - "basic_server/internal/request" - "basic_server/internal/service" "bytes" "encoding/json" "io" @@ -11,6 +8,10 @@ import ( "net/http/httptest" "testing" + "github.com/nix-united/golang-gin-boilerplate/internal/handler" + "github.com/nix-united/golang-gin-boilerplate/internal/request" + "github.com/nix-united/golang-gin-boilerplate/internal/service" + "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/handler/post_handler.go b/internal/handler/post_handler.go index a984f59..5415210 100644 --- a/internal/handler/post_handler.go +++ b/internal/handler/post_handler.go @@ -1,13 +1,14 @@ package handler import ( - "basic_server/internal/model" - "basic_server/internal/request" - "basic_server/internal/response" - "basic_server/internal/service" "net/http" "strconv" + "github.com/nix-united/golang-gin-boilerplate/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/request" + "github.com/nix-united/golang-gin-boilerplate/internal/response" + "github.com/nix-united/golang-gin-boilerplate/internal/service" + jwt "github.com/appleboy/gin-jwt/v2" "github.com/gin-gonic/gin" ) diff --git a/internal/provider/jwt_auth.go b/internal/provider/jwt_auth.go index fdff962..b0b81d1 100644 --- a/internal/provider/jwt_auth.go +++ b/internal/provider/jwt_auth.go @@ -1,14 +1,15 @@ package provider import ( - "basic_server/internal/model" - "basic_server/internal/repository" - "basic_server/internal/request" - "basic_server/internal/utils" "log" "sync" "time" + "github.com/nix-united/golang-gin-boilerplate/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/repository" + "github.com/nix-united/golang-gin-boilerplate/internal/request" + "github.com/nix-united/golang-gin-boilerplate/internal/utils" + jwt "github.com/appleboy/gin-jwt/v2" "github.com/gin-gonic/gin" "golang.org/x/crypto/bcrypt" diff --git a/internal/repository/mocks/user_repository_mock.go b/internal/repository/mocks/user_repository_mock.go index 1d6cc1d..d26525f 100644 --- a/internal/repository/mocks/user_repository_mock.go +++ b/internal/repository/mocks/user_repository_mock.go @@ -1,9 +1,10 @@ package mocks import ( - "basic_server/internal/model" - "basic_server/internal/repository" "errors" + + "github.com/nix-united/golang-gin-boilerplate/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/repository" ) type UserRepositoryMock struct { diff --git a/internal/repository/mocks/users_repository_mockery.go b/internal/repository/mocks/users_repository_mockery.go index 02879bc..4ddcd53 100644 --- a/internal/repository/mocks/users_repository_mockery.go +++ b/internal/repository/mocks/users_repository_mockery.go @@ -3,7 +3,7 @@ package mocks import ( - model "basic_server/internal/model" + model "github.com/nix-united/golang-gin-boilerplate/internal/model" mock "github.com/stretchr/testify/mock" ) diff --git a/internal/repository/post_repository.go b/internal/repository/post_repository.go index f95f658..3a6bf74 100644 --- a/internal/repository/post_repository.go +++ b/internal/repository/post_repository.go @@ -1,7 +1,7 @@ package repository import ( - "basic_server/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/model" "gorm.io/gorm" ) diff --git a/internal/repository/user_repository.go b/internal/repository/user_repository.go index eb1097f..30db6cf 100644 --- a/internal/repository/user_repository.go +++ b/internal/repository/user_repository.go @@ -1,9 +1,10 @@ package repository import ( - "basic_server/internal/model" "errors" + "github.com/nix-united/golang-gin-boilerplate/internal/model" + "gorm.io/gorm" ) diff --git a/internal/repository/user_repository_test.go b/internal/repository/user_repository_test.go index 30b7e99..58b3644 100644 --- a/internal/repository/user_repository_test.go +++ b/internal/repository/user_repository_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "basic_server/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/model" "github.com/DATA-DOG/go-sqlmock" "github.com/stretchr/testify/assert" diff --git a/internal/response/post_responses.go b/internal/response/post_responses.go index 31be491..9aa0d28 100644 --- a/internal/response/post_responses.go +++ b/internal/response/post_responses.go @@ -1,6 +1,6 @@ package response -import "basic_server/internal/model" +import "github.com/nix-united/golang-gin-boilerplate/internal/model" type CreatePostResponse struct { ID uint `json:"id"` diff --git a/internal/server/repository/post_repository.go b/internal/server/repository/post_repository.go index 2d14e72..22a1ae8 100644 --- a/internal/server/repository/post_repository.go +++ b/internal/server/repository/post_repository.go @@ -1,7 +1,7 @@ package repository import ( - "basic_server/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/model" "gorm.io/gorm" ) diff --git a/internal/server/repository/user_repository.go b/internal/server/repository/user_repository.go index a984440..e9ae78b 100644 --- a/internal/server/repository/user_repository.go +++ b/internal/server/repository/user_repository.go @@ -1,9 +1,10 @@ package repository import ( - "basic_server/internal/model" "errors" + "github.com/nix-united/golang-gin-boilerplate/internal/model" + "gorm.io/gorm" ) diff --git a/internal/server/routes.go b/internal/server/routes.go index 5e82b16..5e0d3a1 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -1,11 +1,11 @@ package server import ( - "basic_server/internal/handler" - "basic_server/internal/provider" - "basic_server/internal/repository" - "basic_server/internal/service" - "basic_server/internal/utils" + "github.com/nix-united/golang-gin-boilerplate/internal/handler" + "github.com/nix-united/golang-gin-boilerplate/internal/provider" + "github.com/nix-united/golang-gin-boilerplate/internal/repository" + "github.com/nix-united/golang-gin-boilerplate/internal/service" + "github.com/nix-united/golang-gin-boilerplate/internal/utils" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" diff --git a/internal/server/server.go b/internal/server/server.go index 0587c5d..429f5b3 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -1,8 +1,8 @@ package server import ( - "basic_server/internal/config" - "basic_server/internal/db" + "github.com/nix-united/golang-gin-boilerplate/internal/config" + "github.com/nix-united/golang-gin-boilerplate/internal/db" "github.com/gin-gonic/gin" "gorm.io/gorm" diff --git a/internal/server/service/post_service.go b/internal/server/service/post_service.go index de7f915..c218529 100644 --- a/internal/server/service/post_service.go +++ b/internal/server/service/post_service.go @@ -1,7 +1,7 @@ package service import ( - "basic_server/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/model" "gorm.io/gorm" ) diff --git a/internal/service/errors.go b/internal/service/errors.go index 440b37d..428bdd3 100644 --- a/internal/service/errors.go +++ b/internal/service/errors.go @@ -1,6 +1,6 @@ package service -import "basic_server/internal/errors" +import "github.com/nix-united/golang-gin-boilerplate/internal/errors" type RestError struct { Status int `json:"Status"` diff --git a/internal/service/post_service.go b/internal/service/post_service.go index cab522a..1ef9e96 100644 --- a/internal/service/post_service.go +++ b/internal/service/post_service.go @@ -1,9 +1,10 @@ package service import ( - "basic_server/internal/model" - "basic_server/internal/repository" "net/http" + + "github.com/nix-united/golang-gin-boilerplate/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/repository" ) type PostServiceI interface { diff --git a/internal/service/user_service.go b/internal/service/user_service.go index 6b3bea1..af5fbef 100644 --- a/internal/service/user_service.go +++ b/internal/service/user_service.go @@ -1,9 +1,10 @@ package service import ( - "basic_server/internal/model" - "basic_server/internal/request" "fmt" + + "github.com/nix-united/golang-gin-boilerplate/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/request" ) //go:generate mockgen -source=$GOFILE -destination=user_service_mock_test.go -package=${GOPACKAGE}_test -typed=true diff --git a/internal/service/user_service_mock_test.go b/internal/service/user_service_mock_test.go index 3223d1e..94d8364 100644 --- a/internal/service/user_service_mock_test.go +++ b/internal/service/user_service_mock_test.go @@ -10,7 +10,7 @@ package service_test import ( - model "basic_server/internal/model" + model "github.com/nix-united/golang-gin-boilerplate/internal/model" reflect "reflect" gomock "go.uber.org/mock/gomock" diff --git a/internal/service/user_service_test.go b/internal/service/user_service_test.go index 6c791b3..80f8d3f 100644 --- a/internal/service/user_service_test.go +++ b/internal/service/user_service_test.go @@ -4,10 +4,10 @@ import ( "errors" "testing" - srverrors "basic_server/internal/errors" - "basic_server/internal/model" - "basic_server/internal/request" - "basic_server/internal/service" + srverrors "github.com/nix-united/golang-gin-boilerplate/internal/errors" + "github.com/nix-united/golang-gin-boilerplate/internal/model" + "github.com/nix-united/golang-gin-boilerplate/internal/request" + "github.com/nix-united/golang-gin-boilerplate/internal/service" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" From 20163472c7dda67a95b5c7df087aaac03fc0e828 Mon Sep 17 00:00:00 2001 From: oleksandrkhmil Date: Fri, 10 Jan 2025 17:18:44 +0200 Subject: [PATCH 2/2] feat: add organize-imports to makefile --- Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 074fd9b..0895550 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,15 @@ lint-build: lint-check: @echo "🌀️ code linting..." @docker-compose --file=$(lint_docker_compose_file) run --rm gin-golinter golangci-lint run \ - && echo "✔️ checked without errors" \ - || echo "☢️ code style issues found" - + && echo "✔️ checked without errors" \ + || echo "☢️ code style issues found" lint-fix: @echo "🌀 ️code fixing..." @docker-compose --file=$(lint_docker_compose_file) run --rm gin-golinter golangci-lint run --fix \ && echo "✔️ fixed without errors" \ || (echo "⚠️️ you need to fix above issues manually" && exit 1) - @echo "⚠️️ run \"make lint-check\" again to check what did not fix yet" \ No newline at end of file + @echo "⚠️️ run \"make lint-check\" again to check what did not fix yet" + +organize-imports: + @gci write --custom-order -s standard -s "prefix(github.com/nix-united/golang-gin-boilerplate)" -s default --skip-generated --skip-vendor .