Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions cmd/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import (
"github.com/nix-united/golang-gin-boilerplate/docs"
"github.com/nix-united/golang-gin-boilerplate/internal/config"
"github.com/nix-united/golang-gin-boilerplate/internal/db"
"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/server"
"github.com/nix-united/golang-gin-boilerplate/internal/server/handler"
"github.com/nix-united/golang-gin-boilerplate/internal/server/middleware"
"github.com/nix-united/golang-gin-boilerplate/internal/service/password"
"github.com/nix-united/golang-gin-boilerplate/internal/service/post"
"github.com/nix-united/golang-gin-boilerplate/internal/service/user"
"github.com/nix-united/golang-gin-boilerplate/internal/slogx"
"github.com/nix-united/golang-gin-boilerplate/internal/utils"

"github.com/caarlos0/env/v11"
"github.com/google/uuid"
Expand Down Expand Up @@ -77,26 +76,32 @@ func run() error {
postRepository := repository.NewPostRepository(gormDB)

// Services initialization
bcryptEncoder := utils.NewBcryptEncoder(bcrypt.DefaultCost)
userService := user.NewService(userRepository, bcryptEncoder)
passwordService := password.NewService(bcrypt.DefaultCost)
userService := user.NewService(userRepository, passwordService)
postService := post.NewService(postRepository)

// Handlers initialization
homeHandler := handler.NewHomeHandler()
postHandler := handler.NewPostHandler(postService)
authHandler := handler.NewAuthHandler(userService)
jwtAuth := provider.NewJwtAuth(gormDB)
authHandler, err := handler.NewAuthHandler(handler.AuthHandlerConfig{
ApplicationName: cfg.ApplicationName,
JWTSecret: cfg.AuthConfig.Secret,
JWTTokenDuration: cfg.AuthConfig.TokenDuration,
JWTTokenRefreshDuration: cfg.AuthConfig.RefreshTokenDuration,
UserService: userService,
PasswordService: passwordService,
})
if err != nil {
return fmt.Errorf("new auth handler: %w", err)
}

// Middlewares initialization
requestLoggerMiddleware := middleware.NewRequestLoggerMiddleware(traceStarter)
requestDebuggerMiddleware := middleware.NewRequestDebuggerMiddleware()

// HTTP Server initialization
routes := server.ConfigureRoutes(server.Handlers{
HomeHandler: homeHandler,
AuthHandler: authHandler,
PostHandler: postHandler,
JwtAuthMiddleware: jwtAuth,
RequestLoggingMiddleware: requestLoggerMiddleware.Handle,
RequestDebuggingMiddleware: requestDebuggerMiddleware.Handle,
})
Expand Down
67 changes: 36 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,94 @@ module github.com/nix-united/golang-gin-boilerplate
go 1.24.6

require (
github.com/appleboy/gin-jwt/v2 v2.9.1
github.com/gin-gonic/gin v1.9.1
github.com/gin-gonic/gin v1.11.0
github.com/joho/godotenv v1.5.1
github.com/mailru/easyjson v0.7.7 // indirect
github.com/stretchr/testify v1.11.0
github.com/stretchr/testify v1.11.1
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.2
golang.org/x/crypto v0.41.0
golang.org/x/net v0.43.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/tools v0.36.0 // indirect
golang.org/x/crypto v0.43.0
golang.org/x/net v0.46.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/tools v0.38.0 // indirect
gorm.io/driver/mysql v1.5.2
gorm.io/gorm v1.25.5
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/bytedance/sonic v1.14.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/go-playground/validator/v10 v10.28.0 // indirect
github.com/go-sql-driver/mysql v1.9.3 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/text v0.28.0 // indirect
google.golang.org/protobuf v1.36.7 // indirect
github.com/ugorji/go/codec v1.3.0 // indirect
golang.org/x/arch v0.22.0 // indirect
golang.org/x/text v0.30.0 // indirect
google.golang.org/protobuf v1.36.10 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/appleboy/gin-jwt/v3 v3.2.0
github.com/caarlos0/env/v11 v11.3.1
github.com/ccoveille/go-safecast v1.6.1
github.com/golang-jwt/jwt/v5 v5.3.0
github.com/google/uuid v1.6.0
github.com/pressly/goose/v3 v3.25.0
github.com/testcontainers/testcontainers-go v0.38.0
github.com/testcontainers/testcontainers-go v0.39.0
github.com/testcontainers/testcontainers-go/modules/mysql v0.38.0
go.uber.org/mock v0.6.0
)

require (
dario.cat/mergo v1.0.1 // indirect
dario.cat/mergo v1.0.2 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v28.3.3+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-connections v0.6.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/ebitengine/purego v0.8.4 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.10 // indirect
Expand All @@ -106,22 +107,26 @@ require (
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.55.0 // indirect
github.com/redis/rueidis v1.0.66 // indirect
github.com/sethvargo/go-retry v0.3.0 // indirect
github.com/shirou/gopsutil/v4 v4.25.5 // indirect
github.com/shirou/gopsutil/v4 v4.25.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.37.0 // indirect
go.opentelemetry.io/otel/metric v1.37.0 // indirect
go.opentelemetry.io/otel/sdk v1.37.0 // indirect
go.opentelemetry.io/otel/trace v1.37.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.27.0 // indirect
golang.org/x/sync v0.16.0 // indirect
google.golang.org/grpc v1.75.0 // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/sync v0.17.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250929231259-57b25ae835d4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250929231259-57b25ae835d4 // indirect
)

tool go.uber.org/mock/mockgen
Loading