lifedebugger commited on
Commit
8b40e41
·
1 Parent(s): 7fd7fa5

Deploy files from GitHub repository

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitignore +2 -1
  2. Dockerfile +2 -2
  3. README.md +71 -8
  4. config/config.go +21 -0
  5. config/database_connection_config.go +60 -0
  6. controller/home_controller.go +9 -0
  7. controller/login_controller.go +19 -0
  8. controller/register_controller.go +19 -0
  9. go.mod +2 -2
  10. go.sum +1 -1
  11. middleware/authentication_middleware.go +104 -0
  12. middleware/response_middleware.go +39 -0
  13. models/authentication_payload_model.go +7 -0
  14. models/database_orm_model.go +31 -0
  15. models/exception_model.go +12 -0
  16. models/model.go +1 -0
  17. models/request_model.go +13 -0
  18. models/response_model.go +19 -0
  19. repositories/account_repository.go +24 -0
  20. repositories/repository.go +113 -0
  21. services/login_service.go +47 -0
  22. services/register_service.go +40 -0
  23. services/service.go +31 -0
  24. space/README.md +71 -8
  25. space/config/DatabaseConfig.go +17 -17
  26. space/controller/LoginController.go +2 -2
  27. space/controller/RegisterController.go +2 -2
  28. space/controller/controller.go +3 -3
  29. space/go.mod +26 -26
  30. space/go.sum +50 -72
  31. space/main.go +2 -2
  32. space/middleware/AuthMiddleware.go +13 -12
  33. space/repositories/AccountRepository.go +1 -1
  34. space/repositories/DatabaseScoope.go +1 -1
  35. space/repositories/repositories.go +1 -1
  36. space/router/router.go +2 -2
  37. space/services/LoginService.go +3 -3
  38. space/services/RegisterService.go +3 -3
  39. space/services/services.go +2 -2
  40. space/space/models/ExceptionModel.go +8 -7
  41. space/space/services/RegisterService.go +5 -0
  42. space/space/space/repositories/AccountRepository.go +2 -2
  43. space/space/space/repositories/repositories.go +0 -7
  44. space/space/space/services/LoginService.go +1 -1
  45. space/space/space/services/RegisterService.go +2 -0
  46. space/space/space/space/go.mod +1 -0
  47. space/space/space/space/go.sum +2 -0
  48. space/space/space/space/models/DatabaseModel.go +17 -5
  49. space/space/space/space/repositories/AccountRepository.go +0 -3
  50. space/space/space/space/services/RegisterService.go +3 -2
.gitignore CHANGED
@@ -1,3 +1,4 @@
1
  .env
2
  vendor/
3
- quzuu-be.exe
 
 
1
  .env
2
  vendor/
3
+ quzuu-be.exe
4
+ README.md
Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
- # Gunakan image dasar Golang versi 1.21.6
2
- FROM golang:1.21.6
3
 
4
  # Set working directory
5
  WORKDIR /app
 
1
+ # Gunakan image dasar Golang versi 1.24.1
2
+ FROM golang:1.24.1
3
 
4
  # Set working directory
5
  WORKDIR /app
README.md CHANGED
@@ -1,8 +1,71 @@
1
- ---
2
- title: Quzuu Api Dev
3
- emoji: 🐠
4
- colorFrom: indigo
5
- colorTo: gray
6
- sdk: docker
7
- pinned: false
8
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Golang API Boilerplate
2
+ This is a boilerplate for a RESTful API written in Golang.
3
+
4
+ ## Features
5
+ - [x] JWT Authentication
6
+ - [x] PostgreSQL Database
7
+ - [x] GORM ORM
8
+ - [x] Gin Framework
9
+ - [x] Docker Support
10
+ - [x] Environment Variables
11
+ - [x] Logging
12
+ - [x] Error Handling
13
+
14
+ ## Getting Started
15
+ 1. Clone the repository
16
+ 2. Run `go get` to download the dependencies
17
+ 3. Create a file named `.env` and add the following variables:
18
+ * `DB_HOST`
19
+ * `DB_USER`
20
+ * `DB_PASSWORD`
21
+ * `DB_NAME`
22
+ * `DB_PORT`
23
+ * `SALT`
24
+ * `HOST_ADDRESS`
25
+ * `HOST_PORT`
26
+ * `LOG_PATH`
27
+ 4. Run `go run main.go` to start the server
28
+ 5. Open your browser and navigate to `http://localhost:HOST_PORT`
29
+
30
+ ## API Endpoints
31
+ ### Authentication
32
+ - `POST /login`: Login with email and password
33
+ - `POST /register`: Register a new user
34
+ - `GET /logout`: Logout
35
+
36
+ ### Users
37
+ - `GET /users`: Get all users
38
+ - `GET /users/:id`: Get a user by ID
39
+ - `PUT /users/:id`: Update a user
40
+ - `DELETE /users/:id`: Delete a user
41
+
42
+ ## Docker Support
43
+ You can build a Docker image by running `docker build -t my-api .` and then run it with `docker run -p 8080:8080 my-api`.
44
+
45
+ ## Environment Variables
46
+ You can set the following environment variables:
47
+ - `DB_HOST`
48
+ - `DB_USER`
49
+ - `DB_PASSWORD`
50
+ - `DB_NAME`
51
+ - `DB_PORT`
52
+ - `SALT`
53
+ - `HOST_ADDRESS`
54
+ - `HOST_PORT`
55
+ - `LOG_PATH`
56
+
57
+ ## Logging
58
+ The API uses the `log` package to log errors. You can set the `LOG_PATH` environment variable to specify the log file path.
59
+
60
+ ## Error Handling
61
+ The API uses the `errors` package to handle errors. You can set the `ERROR_PATH` environment variable to specify the error file path.
62
+
63
+ # Command Documentation
64
+
65
+ ## Update Golang Project version
66
+ > go mod edit -go 1.24
67
+ > go mod tidy
68
+
69
+ ## Update all package
70
+ > go get -u ./...
71
+ > go mod tidy
config/config.go ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package config
2
+
3
+ import (
4
+ "os"
5
+
6
+ "github.com/joho/godotenv"
7
+ )
8
+
9
+ var TCP_ADDRESS string
10
+ var LOG_PATH string
11
+ var HOST_ADDRESS string
12
+ var HOST_PORT string
13
+
14
+ func init() {
15
+ godotenv.Load()
16
+ HOST_ADDRESS = os.Getenv("HOST_ADDRESS")
17
+ HOST_PORT = os.Getenv("HOST_PORT")
18
+ TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT
19
+ LOG_PATH = os.Getenv("LOG_PATH")
20
+ // Menampilkan nilai variabel lingkungan
21
+ }
config/database_connection_config.go ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package config
2
+
3
+ import (
4
+ "fmt"
5
+ "log"
6
+ "os"
7
+
8
+ "gorm.io/driver/postgres"
9
+ "gorm.io/gorm"
10
+ "gorm.io/gorm/logger"
11
+
12
+ "api.qobiltu.id/models"
13
+ "github.com/joho/godotenv"
14
+ )
15
+
16
+ var DB *gorm.DB
17
+ var err error
18
+ var Salt string
19
+
20
+ func init() {
21
+ godotenv.Load()
22
+ if err != nil {
23
+ fmt.Println("Gagal membaca file .env")
24
+ return
25
+ }
26
+ os.Setenv("TZ", "Asia/Jakarta")
27
+ dbHost := os.Getenv("DB_HOST")
28
+ dbPort := os.Getenv("DB_PORT")
29
+ dbUser := os.Getenv("DB_USER")
30
+ dbPassword := os.Getenv("DB_PASSWORD")
31
+ dbName := os.Getenv("DB_NAME")
32
+ Salt := os.Getenv("SALT")
33
+ dsn := "host=" + dbHost + " user=" + dbUser + " password=" + dbPassword + " dbname=" + dbName + " port=" + dbPort + " sslmode=disable TimeZone=Asia/Jakarta"
34
+ DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{TranslateError: true})
35
+ if err != nil {
36
+ panic(err)
37
+ }
38
+ if Salt == "" {
39
+ Salt = "D3f4u|t"
40
+ }
41
+
42
+ // Call AutoMigrateAll to perform auto-migration
43
+ AutoMigrateAll(DB)
44
+ }
45
+
46
+ func AutoMigrateAll(db *gorm.DB) {
47
+ // Enable logger to see SQL logs
48
+ db.Logger.LogMode(logger.Info)
49
+
50
+ // Auto-migrate all models
51
+ err := db.AutoMigrate(
52
+ &models.Account{},
53
+ &models.AccountDetails{},
54
+ )
55
+ if err != nil {
56
+ log.Fatal(err)
57
+ }
58
+
59
+ fmt.Println("Migration completed successfully.")
60
+ }
controller/home_controller.go ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ package controller
2
+
3
+ import "github.com/gin-gonic/gin"
4
+
5
+ func HomeController(c *gin.Context) {
6
+ c.JSON(200, gin.H{
7
+ "message": "Api Qobiltu 2025!",
8
+ })
9
+ }
controller/login_controller.go ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package controller
2
+
3
+ import (
4
+ "api.qobiltu.id/models"
5
+ "api.qobiltu.id/services"
6
+ "github.com/gin-gonic/gin"
7
+ )
8
+
9
+ func LoginController(c *gin.Context) {
10
+ authentication := services.AuthenticationService{}
11
+ loginController := Controller[models.LoginRequest, services.LoginConstructor, models.AuthenticatedUser]{
12
+ Service: &authentication.Service,
13
+ }
14
+ loginController.RequestJSON(c, func() {
15
+ loginController.Service.Constructor.Email = loginController.Request.Email
16
+ loginController.Service.Constructor.Password = loginController.Request.Password
17
+ authentication.Authenticate()
18
+ })
19
+ }
controller/register_controller.go ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package controller
2
+
3
+ import (
4
+ "api.qobiltu.id/models"
5
+ "api.qobiltu.id/services"
6
+ "github.com/gin-gonic/gin"
7
+ )
8
+
9
+ func RegisterController(c *gin.Context) {
10
+ register := services.RegisterService{}
11
+ registerController := Controller[models.RegisterRequest, models.Account, models.Account]{
12
+ Service: &register.Service,
13
+ }
14
+ registerController.RequestJSON(c, func() {
15
+ registerController.Service.Constructor.Password = registerController.Request.Password
16
+ registerController.Service.Constructor.Email = registerController.Request.Email
17
+ register.Create()
18
+ })
19
+ }
go.mod CHANGED
@@ -1,6 +1,6 @@
1
  module api.qobiltu.id
2
 
3
- go 1.24
4
 
5
  require (
6
  github.com/gin-gonic/gin v1.10.0
@@ -46,4 +46,4 @@ require (
46
  golang.org/x/text v0.23.0 // indirect
47
  google.golang.org/protobuf v1.36.5 // indirect
48
  gopkg.in/yaml.v3 v3.0.1 // indirect
49
- )
 
1
  module api.qobiltu.id
2
 
3
+ go 1.24.0
4
 
5
  require (
6
  github.com/gin-gonic/gin v1.10.0
 
46
  golang.org/x/text v0.23.0 // indirect
47
  google.golang.org/protobuf v1.36.5 // indirect
48
  gopkg.in/yaml.v3 v3.0.1 // indirect
49
+ )
go.sum CHANGED
@@ -115,4 +115,4 @@ gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
115
  gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
116
  gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
117
  gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
118
- nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
 
115
  gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
116
  gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
117
  gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
118
+ nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
middleware/authentication_middleware.go ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // auth/auth.go
2
+
3
+ package middleware
4
+
5
+ import (
6
+ "errors"
7
+ "time"
8
+
9
+ "api.qobiltu.id/config"
10
+ "api.qobiltu.id/models"
11
+ "github.com/gin-gonic/gin"
12
+ "github.com/golang-jwt/jwt/v5"
13
+ "golang.org/x/crypto/bcrypt"
14
+ )
15
+
16
+ // Define a secret key for signing the JWT token
17
+ var salt = config.Salt
18
+ var secretKey = []byte(salt)
19
+
20
+ // GenerateToken generates a JWT token for the given user
21
+ func GenerateToken(user *models.Account) (string, error) {
22
+
23
+ // Create a new token
24
+ token := jwt.New(jwt.SigningMethodHS256)
25
+
26
+ // Set claims
27
+ claims := token.Claims.(jwt.MapClaims)
28
+ claims["id"] = user.Id
29
+ claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours
30
+
31
+ // Sign the token with the secret key
32
+ tokenString, err := token.SignedString(secretKey)
33
+ if err != nil {
34
+ return "", err
35
+ }
36
+
37
+ return tokenString, nil
38
+ }
39
+
40
+ // VerifyPassword verifies if the provided password matches the hashed password
41
+ func VerifyPassword(hashedPassword, password string) error {
42
+ err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
43
+ if err != nil {
44
+ return errors.New("invalid password")
45
+ }
46
+ return nil
47
+ }
48
+ func HashPassword(password string) (string, error) {
49
+ bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
50
+ return string(bytes), err
51
+ }
52
+
53
+ type CustomClaims struct {
54
+ jwt.RegisteredClaims
55
+ UserID int `json:"id"`
56
+ }
57
+
58
+ func VerifyToken(bearer_token string) (int, string, error) {
59
+ // fmt.Println(bearer_token)
60
+ token, err := jwt.ParseWithClaims(bearer_token, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) {
61
+ return secretKey, nil
62
+ })
63
+ if err != nil {
64
+ return 0, "invalid-token", err
65
+ }
66
+
67
+ // Extract the claims
68
+ claims, ok := token.Claims.(*CustomClaims)
69
+ if !ok || !token.Valid {
70
+ return 0, "invalid-token", err
71
+ }
72
+ if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) {
73
+ return 0, "expired", err
74
+ }
75
+
76
+ return claims.UserID, "valid", err
77
+ }
78
+
79
+ func AuthUser(c *gin.Context) {
80
+ var currAccData models.AccountData
81
+ if c.Request.Header["Auth-Bearer-Token"] != nil {
82
+ token := c.Request.Header["Auth-Bearer-Token"]
83
+ currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0])
84
+ // fmt.Println("Verify Status :", currAccData.verifyStatus)
85
+ if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" {
86
+ currAccData.UserID = 0
87
+ message := "Your session is expired, Please re-Login!"
88
+ SendJSON401(c, &currAccData.VerifyStatus, &message)
89
+ c.Abort()
90
+ return
91
+ }
92
+ } else {
93
+ currAccData.UserID = 0
94
+ currAccData.VerifyStatus = "no-token"
95
+ currAccData.ErrVerif = nil
96
+ message := "You have to Login First!"
97
+ SendJSON401(c, &currAccData.VerifyStatus, &message)
98
+ c.Abort()
99
+ return
100
+ }
101
+
102
+ c.Set("accountData", currAccData)
103
+ c.Next()
104
+ }
middleware/response_middleware.go ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package middleware
2
+
3
+ import (
4
+ "net/http"
5
+
6
+ "github.com/gin-gonic/gin"
7
+ )
8
+
9
+ // SendJSON200 sends a JSON response with HTTP status code 200
10
+ func SendJSON200(c *gin.Context, data interface{}) {
11
+ c.JSON(http.StatusOK, gin.H{"status": "success", "data": data})
12
+ }
13
+
14
+ // SendJSON400 sends a JSON response with HTTP status code 400
15
+ func SendJSON400(c *gin.Context, error_status *string, message *string) {
16
+ c.JSON(http.StatusBadRequest, gin.H{"status": "error", "error-status": error_status, "message": message})
17
+ }
18
+
19
+ // SendJSON401 sends a JSON response with HTTP status code 401
20
+ func SendJSON401(c *gin.Context, error_status *string, message *string) {
21
+ c.JSON(http.StatusUnauthorized, gin.H{"status": "error", "error-status": error_status, "message": message})
22
+ }
23
+
24
+ // SendJSON403 sends a JSON response with HTTP status code 403
25
+ func SendJSON403(c *gin.Context, message *string) {
26
+ c.JSON(http.StatusForbidden, gin.H{"status": "error", "message": message})
27
+ }
28
+
29
+ // SendJSON404 sends a JSON response with HTTP status code 404
30
+ func SendJSON404(c *gin.Context, message *string) {
31
+ c.JSON(http.StatusNotFound, gin.H{"status": "error", "message": message})
32
+ }
33
+
34
+ // SendJSON500 sends a JSON response with HTTP status code 500
35
+ func SendJSON500(c *gin.Context, error_status *string, message *string) {
36
+ c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "error-status": error_status, "message": message})
37
+ }
38
+
39
+ // JSONResponseMiddleware is a middleware that provides functions for sending JSON responses
models/authentication_payload_model.go ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ type AccountData struct {
4
+ UserID int
5
+ VerifyStatus string
6
+ ErrVerif error
7
+ }
models/database_orm_model.go ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ import (
4
+ "time"
5
+
6
+ uuid "github.com/satori/go.uuid"
7
+ )
8
+
9
+ type Account struct {
10
+ Id uint `gorm:"primaryKey" json:"id"`
11
+ UUID uuid.UUID `gorm:"type:uuid" json:"uuid" `
12
+ Email string `gorm:"uniqueIndex" json:"email"`
13
+ Password string `json:"password"`
14
+ IsEmailVerified bool `json:"is_email_verified"`
15
+ CreatedAt time.Time `json:"created_at"`
16
+ DeletedAt time.Time `json:"deleted_at"`
17
+ }
18
+
19
+ type AccountDetails struct {
20
+ IDDetail uint `gorm:"primaryKey" json:"id_detail"`
21
+ Account_id uint `json:"id_account"`
22
+ Province string `json:"province"`
23
+ City string `json:"city"`
24
+ Institution string `json:"institution"`
25
+ UpdatedAt time.Time `json:"updated_at"`
26
+ DeletedAt time.Time `json:"deleted_at"`
27
+ }
28
+
29
+ // Gorm table name settings
30
+ func (Account) TableName() string { return "account" }
31
+ func (AccountDetails) TableName() string { return "account_details" }
models/exception_model.go ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ type Exception struct {
4
+ Unauthorized bool `json:"unauthorized,omitempty"`
5
+ BadRequest bool `json:"bad_request,omitempty"`
6
+ DataNotFound bool `json:"data_not_found,omitempty"`
7
+ InternalServerError bool `json:"internal_server_error,omitempty"`
8
+ DataDuplicate bool `json:"data_duplicate,omitempty"`
9
+ QueryError bool `json:"query_error,omitempty"`
10
+ InvalidPasswordLength bool `json:"invalid_password_length,omitempty"`
11
+ Message string `json:"message,omitempty"`
12
+ }
models/model.go ADDED
@@ -0,0 +1 @@
 
 
1
+ package models
models/request_model.go ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ type LoginRequest struct {
4
+ Email string `json:"email" binding:"required"`
5
+ Password string `json:"password" binding:"required"`
6
+ }
7
+
8
+ type RegisterRequest struct {
9
+ Name string `json:"name"`
10
+ Email string `json:"email" binding:"required,email"`
11
+ Phone int `json:"phone"`
12
+ Password string `json:"password" binding:"required"`
13
+ }
models/response_model.go ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ type SuccessResponse struct {
4
+ Status string `json:"status"`
5
+ Message string `json:"message"`
6
+ Data any `json:"data"`
7
+ MetaData any `json:"meta_data"`
8
+ }
9
+
10
+ type ErrorResponse struct {
11
+ Status string `json:"status"`
12
+ Message string `json:"message"`
13
+ Errors Exception `json:"errors"`
14
+ MetaData any `json:"meta_data"`
15
+ }
16
+ type AuthenticatedUser struct {
17
+ Account Account `json:"account"`
18
+ Token string `json:"token"`
19
+ }
repositories/account_repository.go ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package repositories
2
+
3
+ import (
4
+ "api.qobiltu.id/models"
5
+ )
6
+
7
+ func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
8
+ repo := Construct[models.Account, models.Account](
9
+ models.Account{Email: email},
10
+ )
11
+ repo.Transactions(
12
+ WhereGivenConstructor[models.Account, models.Account],
13
+ Find[models.Account, models.Account],
14
+ )
15
+ return *repo
16
+ }
17
+
18
+ func CreateAccount(account models.Account) Repository[models.Account, models.Account] {
19
+ repo := Construct[models.Account, models.Account](
20
+ account,
21
+ )
22
+ Create(repo)
23
+ return *repo
24
+ }
repositories/repository.go ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package repositories
2
+
3
+ import (
4
+ "api.qobiltu.id/config"
5
+ "gorm.io/gorm"
6
+ )
7
+
8
+ type Repositories interface {
9
+ FindAllPaginate()
10
+ Where()
11
+ Find()
12
+ Create()
13
+ Update()
14
+ CustomQuery()
15
+ Delete()
16
+ }
17
+ type PaginationConstructor struct {
18
+ Limit int
19
+ Offset int
20
+ Filter string
21
+ }
22
+
23
+ type CustomQueryConstructor struct {
24
+ SQL string
25
+ Values interface{}
26
+ }
27
+
28
+ type Repository[TConstructor any, TResult any] struct {
29
+ Constructor TConstructor
30
+ Pagination PaginationConstructor
31
+ CustomQuery CustomQueryConstructor
32
+ Result TResult
33
+ Transaction *gorm.DB
34
+ RowsCount int
35
+ NoRecord bool
36
+ RowsError error
37
+ }
38
+
39
+ func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repository[TConstructor, TResult] {
40
+ if len(constructor) == 1 {
41
+ return &Repository[TConstructor, TResult]{
42
+ Constructor: constructor[0],
43
+ Transaction: config.DB,
44
+ }
45
+ }
46
+ return &Repository[TConstructor, TResult]{
47
+ Constructor: constructor[0],
48
+ Transaction: config.DB.Begin(),
49
+ }
50
+ }
51
+ func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) {
52
+ for _, tx := range transactions {
53
+ repo.Transaction = tx(repo)
54
+ if repo.RowsError != nil {
55
+ return
56
+ }
57
+ }
58
+ }
59
+ func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
60
+ tx := repo.Transaction.Where(&repo.Constructor)
61
+ repo.RowsCount = int(tx.RowsAffected)
62
+ repo.NoRecord = repo.RowsCount == 0
63
+ repo.RowsError = tx.Error
64
+ return tx
65
+ }
66
+ func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
67
+ tx := repo.Transaction.Find(&repo.Result)
68
+ repo.RowsCount = int(tx.RowsAffected)
69
+ repo.NoRecord = repo.RowsCount == 0
70
+ repo.RowsError = tx.Error
71
+ return tx
72
+ }
73
+
74
+ func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
75
+ tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result)
76
+ repo.RowsCount = int(tx.RowsAffected)
77
+ repo.NoRecord = repo.RowsCount == 0
78
+ repo.RowsError = tx.Error
79
+ return tx
80
+ }
81
+
82
+ func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB {
83
+ tx := repo.Transaction.Create(&repo.Constructor)
84
+ repo.RowsCount = int(tx.RowsAffected)
85
+ repo.NoRecord = repo.RowsCount == 0
86
+ repo.RowsError = tx.Error
87
+ repo.Result = repo.Constructor
88
+ return tx
89
+ }
90
+
91
+ func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB {
92
+ tx := repo.Transaction.Save(&repo.Constructor)
93
+ repo.RowsCount = int(tx.RowsAffected)
94
+ repo.NoRecord = repo.RowsCount == 0
95
+ repo.RowsError = tx.Error
96
+ return tx
97
+ }
98
+
99
+ func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB {
100
+ tx := repo.Transaction.Delete(&repo.Constructor)
101
+ repo.RowsCount = int(tx.RowsAffected)
102
+ repo.NoRecord = repo.RowsCount == 0
103
+ repo.RowsError = tx.Error
104
+ return tx
105
+ }
106
+
107
+ func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
108
+ tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result)
109
+ repo.RowsCount = int(tx.RowsAffected)
110
+ repo.NoRecord = repo.RowsCount == 0
111
+ repo.RowsError = tx.Error
112
+ return tx
113
+ }
services/login_service.go ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package services
2
+
3
+ import (
4
+ "errors"
5
+
6
+ "api.qobiltu.id/middleware"
7
+ "api.qobiltu.id/models"
8
+ "api.qobiltu.id/repositories"
9
+ )
10
+
11
+ type LoginConstructor struct {
12
+ Email string
13
+ Password string
14
+ }
15
+
16
+ type AuthenticationService struct {
17
+ Service[LoginConstructor, models.AuthenticatedUser]
18
+ }
19
+
20
+ func (s *AuthenticationService) Authenticate() {
21
+ accountData := repositories.GetAccountbyEmail(s.Constructor.Email)
22
+ if accountData.NoRecord {
23
+ s.Exception.DataNotFound = true
24
+ s.Exception.Message = "there is no account with given credentials!"
25
+ return
26
+ }
27
+ if middleware.VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil {
28
+ s.Exception.Unauthorized = true
29
+ s.Exception.Message = "incorrect password!"
30
+ return
31
+ }
32
+
33
+ token, err_tok := middleware.GenerateToken(&accountData.Result)
34
+
35
+ if err_tok != nil {
36
+ s.Error = errors.Join(s.Error, err_tok)
37
+ }
38
+
39
+ accountData.Result.Password = "SECRET"
40
+ s.Result = models.AuthenticatedUser{
41
+ Account: accountData.Result,
42
+ Token: token,
43
+ }
44
+ s.Error = accountData.RowsError
45
+ }
46
+
47
+ // LoginHandler handles user login
services/register_service.go ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package services
2
+
3
+ import (
4
+ "errors"
5
+
6
+ "api.qobiltu.id/middleware"
7
+ "api.qobiltu.id/models"
8
+ "api.qobiltu.id/repositories"
9
+ uuid "github.com/satori/go.uuid"
10
+ "gorm.io/gorm"
11
+ )
12
+
13
+ type RegisterService struct {
14
+ Service[models.Account, models.Account]
15
+ }
16
+
17
+ func (s *RegisterService) Create() {
18
+ if len(s.Constructor.Password) < 8 {
19
+ s.Exception.InvalidPasswordLength = true
20
+ s.Exception.Message = "Password must have at least 8 characters!"
21
+ return
22
+ }
23
+ hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
24
+ s.Error = err_hash
25
+ s.Constructor.Password = hashed_password
26
+ s.Constructor.UUID = uuid.NewV4()
27
+ accountCreated := repositories.CreateAccount(s.Constructor)
28
+ if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
29
+ s.Exception.DataDuplicate = true
30
+ s.Exception.Message = "Account with email " + s.Constructor.Email + " already exists!"
31
+ return
32
+ } else if errors.Is(accountCreated.RowsError, gorm.ErrModelAccessibleFieldsRequired) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidData) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidValue) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidField) {
33
+ s.Exception.BadRequest = true
34
+ s.Exception.Message = "Bad request!"
35
+ return
36
+ }
37
+ s.Error = accountCreated.RowsError
38
+ s.Result = accountCreated.Result
39
+ s.Result.Password = "SECRET"
40
+ }
services/service.go ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package services
2
+
3
+ import "api.qobiltu.id/models"
4
+
5
+ type (
6
+ Services interface {
7
+ Retrieve()
8
+ Update()
9
+ Create()
10
+ Delete()
11
+ Validate()
12
+ Authenticate()
13
+ Authorize()
14
+ }
15
+ Service[TConstructor any, TResult any] struct {
16
+ Constructor TConstructor
17
+ Result TResult
18
+ Exception models.Exception
19
+ Error error
20
+ }
21
+ )
22
+
23
+ func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Service[TConstructor, TResult] {
24
+ if len(constructor) == 1 {
25
+ return &Service[TConstructor, TResult]{}
26
+ }
27
+
28
+ return &Service[TConstructor, TResult]{
29
+ Constructor: constructor[0],
30
+ }
31
+ }
space/README.md CHANGED
@@ -1,8 +1,71 @@
1
- ---
2
- title: Quzuu Api Dev
3
- emoji: 🐠
4
- colorFrom: indigo
5
- colorTo: gray
6
- sdk: docker
7
- pinned: false
8
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Golang API Boilerplate
2
+ This is a boilerplate for a RESTful API written in Golang.
3
+
4
+ ## Features
5
+ - [x] JWT Authentication
6
+ - [x] PostgreSQL Database
7
+ - [x] GORM ORM
8
+ - [x] Gin Framework
9
+ - [x] Docker Support
10
+ - [x] Environment Variables
11
+ - [x] Logging
12
+ - [x] Error Handling
13
+
14
+ ## Getting Started
15
+ 1. Clone the repository
16
+ 2. Run `go get` to download the dependencies
17
+ 3. Create a file named `.env` and add the following variables:
18
+ * `DB_HOST`
19
+ * `DB_USER`
20
+ * `DB_PASSWORD`
21
+ * `DB_NAME`
22
+ * `DB_PORT`
23
+ * `SALT`
24
+ * `HOST_ADDRESS`
25
+ * `HOST_PORT`
26
+ * `LOG_PATH`
27
+ 4. Run `go run main.go` to start the server
28
+ 5. Open your browser and navigate to `http://localhost:HOST_PORT`
29
+
30
+ ## API Endpoints
31
+ ### Authentication
32
+ - `POST /login`: Login with email and password
33
+ - `POST /register`: Register a new user
34
+ - `GET /logout`: Logout
35
+
36
+ ### Users
37
+ - `GET /users`: Get all users
38
+ - `GET /users/:id`: Get a user by ID
39
+ - `PUT /users/:id`: Update a user
40
+ - `DELETE /users/:id`: Delete a user
41
+
42
+ ## Docker Support
43
+ You can build a Docker image by running `docker build -t my-api .` and then run it with `docker run -p 8080:8080 my-api`.
44
+
45
+ ## Environment Variables
46
+ You can set the following environment variables:
47
+ - `DB_HOST`
48
+ - `DB_USER`
49
+ - `DB_PASSWORD`
50
+ - `DB_NAME`
51
+ - `DB_PORT`
52
+ - `SALT`
53
+ - `HOST_ADDRESS`
54
+ - `HOST_PORT`
55
+ - `LOG_PATH`
56
+
57
+ ## Logging
58
+ The API uses the `log` package to log errors. You can set the `LOG_PATH` environment variable to specify the log file path.
59
+
60
+ ## Error Handling
61
+ The API uses the `errors` package to handle errors. You can set the `ERROR_PATH` environment variable to specify the error file path.
62
+
63
+ # Command Documentation
64
+
65
+ ## Update Golang Project version
66
+ > go mod edit -go 1.24
67
+ > go mod tidy
68
+
69
+ ## Update all package
70
+ > go get -u ./...
71
+ > go mod tidy
space/config/DatabaseConfig.go CHANGED
@@ -9,26 +9,10 @@ import (
9
  "gorm.io/gorm"
10
  "gorm.io/gorm/logger"
11
 
 
12
  "github.com/joho/godotenv"
13
- "go-dp.abdanhafidz.com/models"
14
  )
15
 
16
- func AutoMigrateAll(db *gorm.DB) {
17
- // Enable logger to see SQL logs
18
- db.Logger.LogMode(logger.Info)
19
-
20
- // Auto-migrate all models
21
- err := db.AutoMigrate(
22
- &models.Account{},
23
- &models.AccountDetails{},
24
- )
25
- if err != nil {
26
- log.Fatal(err)
27
- }
28
-
29
- fmt.Println("Migration completed successfully.")
30
- }
31
-
32
  var DB *gorm.DB
33
  var err error
34
  var Salt string
@@ -58,3 +42,19 @@ func init() {
58
  // Call AutoMigrateAll to perform auto-migration
59
  AutoMigrateAll(DB)
60
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  "gorm.io/gorm"
10
  "gorm.io/gorm/logger"
11
 
12
+ "api.qobiltu.id/models"
13
  "github.com/joho/godotenv"
 
14
  )
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  var DB *gorm.DB
17
  var err error
18
  var Salt string
 
42
  // Call AutoMigrateAll to perform auto-migration
43
  AutoMigrateAll(DB)
44
  }
45
+
46
+ func AutoMigrateAll(db *gorm.DB) {
47
+ // Enable logger to see SQL logs
48
+ db.Logger.LogMode(logger.Info)
49
+
50
+ // Auto-migrate all models
51
+ err := db.AutoMigrate(
52
+ &models.Account{},
53
+ &models.AccountDetails{},
54
+ )
55
+ if err != nil {
56
+ log.Fatal(err)
57
+ }
58
+
59
+ fmt.Println("Migration completed successfully.")
60
+ }
space/controller/LoginController.go CHANGED
@@ -1,9 +1,9 @@
1
  package controller
2
 
3
  import (
 
 
4
  "github.com/gin-gonic/gin"
5
- "go-dp.abdanhafidz.com/models"
6
- "go-dp.abdanhafidz.com/services"
7
  )
8
 
9
  func LoginController(c *gin.Context) {
 
1
  package controller
2
 
3
  import (
4
+ "api.qobiltu.id/models"
5
+ "api.qobiltu.id/services"
6
  "github.com/gin-gonic/gin"
 
 
7
  )
8
 
9
  func LoginController(c *gin.Context) {
space/controller/RegisterController.go CHANGED
@@ -1,9 +1,9 @@
1
  package controller
2
 
3
  import (
 
 
4
  "github.com/gin-gonic/gin"
5
- "go-dp.abdanhafidz.com/models"
6
- "go-dp.abdanhafidz.com/services"
7
  )
8
 
9
  func RegisterController(c *gin.Context) {
 
1
  package controller
2
 
3
  import (
4
+ "api.qobiltu.id/models"
5
+ "api.qobiltu.id/services"
6
  "github.com/gin-gonic/gin"
 
 
7
  )
8
 
9
  func RegisterController(c *gin.Context) {
space/controller/controller.go CHANGED
@@ -1,10 +1,10 @@
1
  package controller
2
 
3
  import (
 
 
 
4
  "github.com/gin-gonic/gin"
5
- "go-dp.abdanhafidz.com/models"
6
- "go-dp.abdanhafidz.com/services"
7
- "go-dp.abdanhafidz.com/utils"
8
  )
9
 
10
  type (
 
1
  package controller
2
 
3
  import (
4
+ "api.qobiltu.id/models"
5
+ "api.qobiltu.id/services"
6
+ "api.qobiltu.id/utils"
7
  "github.com/gin-gonic/gin"
 
 
 
8
  )
9
 
10
  type (
space/go.mod CHANGED
@@ -1,49 +1,49 @@
1
- module go-dp.abdanhafidz.com
2
 
3
- go 1.21.0
4
 
5
  require (
6
- github.com/dgrijalva/jwt-go v3.2.0+incompatible
7
- github.com/gin-gonic/gin v1.9.1
8
  github.com/joho/godotenv v1.5.1
9
- golang.org/x/crypto v0.32.0
10
- gorm.io/driver/postgres v1.5.4
11
- gorm.io/gorm v1.25.5
 
12
  )
13
 
14
  require (
15
- github.com/bytedance/sonic v1.10.2 // indirect
16
- github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
17
- github.com/chenzhuoyu/iasm v0.9.0 // indirect
18
  github.com/gabriel-vasile/mimetype v1.4.8 // indirect
19
- github.com/gin-contrib/sse v0.1.0 // indirect
20
  github.com/go-playground/locales v0.14.1 // indirect
21
  github.com/go-playground/universal-translator v0.18.1 // indirect
22
  github.com/go-playground/validator/v10 v10.25.0 // indirect
23
- github.com/goccy/go-json v0.10.2 // indirect
24
  github.com/jackc/pgpassfile v1.0.0 // indirect
25
- github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
26
- github.com/jackc/pgx/v5 v5.5.0 // indirect
27
- github.com/jackc/puddle/v2 v2.2.1 // indirect
28
  github.com/jinzhu/inflection v1.0.0 // indirect
29
  github.com/jinzhu/now v1.1.5 // indirect
30
  github.com/json-iterator/go v1.1.12 // indirect
31
- github.com/klauspost/cpuid/v2 v2.2.6 // indirect
32
  github.com/kr/text v0.2.0 // indirect
33
  github.com/leodido/go-urn v1.4.0 // indirect
34
  github.com/mattn/go-isatty v0.0.20 // indirect
35
  github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
36
  github.com/modern-go/reflect2 v1.0.2 // indirect
37
- github.com/pelletier/go-toml/v2 v2.1.0 // indirect
38
  github.com/rogpeppe/go-internal v1.11.0 // indirect
39
- github.com/satori/go.uuid v1.2.0 // indirect
40
  github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
41
- github.com/ugorji/go/codec v1.2.11 // indirect
42
- golang.org/x/arch v0.6.0 // indirect
43
- golang.org/x/net v0.34.0 // indirect
44
- golang.org/x/sync v0.10.0 // indirect
45
- golang.org/x/sys v0.29.0 // indirect
46
- golang.org/x/text v0.21.0 // indirect
47
- google.golang.org/protobuf v1.31.0 // indirect
48
  gopkg.in/yaml.v3 v3.0.1 // indirect
49
- )
 
1
+ module api.qobiltu.id
2
 
3
+ go 1.24.0
4
 
5
  require (
6
+ github.com/gin-gonic/gin v1.10.0
7
+ github.com/golang-jwt/jwt/v5 v5.2.1
8
  github.com/joho/godotenv v1.5.1
9
+ github.com/satori/go.uuid v1.2.0
10
+ golang.org/x/crypto v0.36.0
11
+ gorm.io/driver/postgres v1.5.11
12
+ gorm.io/gorm v1.25.12
13
  )
14
 
15
  require (
16
+ github.com/bytedance/sonic v1.13.1 // indirect
17
+ github.com/bytedance/sonic/loader v0.2.4 // indirect
18
+ github.com/cloudwego/base64x v0.1.5 // indirect
19
  github.com/gabriel-vasile/mimetype v1.4.8 // indirect
20
+ github.com/gin-contrib/sse v1.0.0 // indirect
21
  github.com/go-playground/locales v0.14.1 // indirect
22
  github.com/go-playground/universal-translator v0.18.1 // indirect
23
  github.com/go-playground/validator/v10 v10.25.0 // indirect
24
+ github.com/goccy/go-json v0.10.5 // indirect
25
  github.com/jackc/pgpassfile v1.0.0 // indirect
26
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
27
+ github.com/jackc/pgx/v5 v5.7.2 // indirect
28
+ github.com/jackc/puddle/v2 v2.2.2 // indirect
29
  github.com/jinzhu/inflection v1.0.0 // indirect
30
  github.com/jinzhu/now v1.1.5 // indirect
31
  github.com/json-iterator/go v1.1.12 // indirect
32
+ github.com/klauspost/cpuid/v2 v2.2.10 // indirect
33
  github.com/kr/text v0.2.0 // indirect
34
  github.com/leodido/go-urn v1.4.0 // indirect
35
  github.com/mattn/go-isatty v0.0.20 // indirect
36
  github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
37
  github.com/modern-go/reflect2 v1.0.2 // indirect
38
+ github.com/pelletier/go-toml/v2 v2.2.3 // indirect
39
  github.com/rogpeppe/go-internal v1.11.0 // indirect
 
40
  github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
41
+ github.com/ugorji/go/codec v1.2.12 // indirect
42
+ golang.org/x/arch v0.15.0 // indirect
43
+ golang.org/x/net v0.37.0 // indirect
44
+ golang.org/x/sync v0.12.0 // indirect
45
+ golang.org/x/sys v0.31.0 // indirect
46
+ golang.org/x/text v0.23.0 // indirect
47
+ google.golang.org/protobuf v1.36.5 // indirect
48
  gopkg.in/yaml.v3 v3.0.1 // indirect
49
+ )
space/go.sum CHANGED
@@ -1,51 +1,44 @@
1
- github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
2
- github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
3
- github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE=
4
- github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
5
- github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
6
- github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
7
- github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
8
- github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
9
- github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo=
10
- github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
11
  github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
12
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
14
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
15
- github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
16
- github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
17
- github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
18
- github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
19
  github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
20
  github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
21
- github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
22
- github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
23
- github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
24
- github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
25
  github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
26
  github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
27
  github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
28
  github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
29
  github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
30
  github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
31
- github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE=
32
- github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
33
  github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
34
  github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
35
- github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
36
- github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
37
- github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 
38
  github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
39
  github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
40
  github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
41
  github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
42
  github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
43
- github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
44
- github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
45
- github.com/jackc/pgx/v5 v5.5.0 h1:NxstgwndsTRy7eq9/kqYc/BZh5w2hHJV86wjvO+1xPw=
46
- github.com/jackc/pgx/v5 v5.5.0/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
47
- github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
48
- github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
49
  github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
50
  github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
51
  github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@@ -55,15 +48,13 @@ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA
55
  github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
56
  github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
57
  github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
58
- github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
59
- github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
60
  github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
61
  github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
62
  github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
63
  github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
64
  github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
65
- github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
66
- github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
67
  github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
68
  github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
69
  github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
@@ -73,8 +64,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
73
  github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
74
  github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
75
  github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
76
- github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
77
- github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
78
  github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
79
  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
80
  github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
@@ -84,57 +75,44 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh
84
  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
85
  github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
86
  github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
 
87
  github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
88
  github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
89
  github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
90
  github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
91
  github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
92
- github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
93
- github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
94
  github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 
 
95
  github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
96
  github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
97
- github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
98
- github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
99
- golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
100
- golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc=
101
- golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
102
- golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
103
- golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
104
- golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
105
- golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
106
- golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
107
- golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
108
- golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
109
- golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
110
- golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
111
- golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
112
- golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
113
- golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
114
- golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
115
  golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
116
- golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
117
- golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
118
- golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
119
- golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
120
- golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
121
- golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
122
- golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
123
- golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
124
  golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
125
  golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
126
- google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
127
- google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
128
- google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
129
  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
130
  gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
131
  gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
132
  gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
133
  gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
134
  gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
135
- gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo=
136
- gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0=
137
- gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
138
- gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
139
- nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
140
- rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
 
1
+ github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g=
2
+ github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
3
+ github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
4
+ github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
5
+ github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
6
+ github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
7
+ github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
8
+ github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
 
 
9
  github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
10
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
12
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 
 
 
 
13
  github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
14
  github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
15
+ github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
16
+ github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
17
+ github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
18
+ github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
19
  github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
20
  github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
21
  github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
22
  github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
23
  github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
24
  github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
 
 
25
  github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
26
  github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
27
+ github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
28
+ github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
29
+ github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
30
+ github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
31
  github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
32
  github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
33
  github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
34
  github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
35
  github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
36
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
37
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
38
+ github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
39
+ github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
40
+ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
41
+ github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
42
  github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
43
  github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
44
  github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 
48
  github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
49
  github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
50
  github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
51
+ github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
52
+ github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
53
  github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
54
  github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
55
  github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
56
  github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
57
  github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
 
 
58
  github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
59
  github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
60
  github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 
64
  github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
65
  github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
66
  github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
67
+ github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
68
+ github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
69
  github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
70
  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
71
  github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
 
75
  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
76
  github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
77
  github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
78
+ github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
79
  github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
80
  github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
81
  github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
82
  github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
83
  github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 
 
84
  github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
85
+ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
86
+ github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
87
  github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
88
  github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
89
+ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
90
+ github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
91
+ golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw=
92
+ golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE=
93
+ golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
94
+ golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
95
+ golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
96
+ golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
97
+ golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
98
+ golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
 
 
 
 
 
 
 
 
99
  golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
100
+ golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
101
+ golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
102
+ golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
103
+ golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
 
 
 
 
104
  golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
105
  golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
106
+ google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
107
+ google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
 
108
  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
109
  gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
110
  gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
111
  gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
112
  gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
113
  gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
114
+ gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
115
+ gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
116
+ gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
117
+ gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
118
+ nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
 
space/main.go CHANGED
@@ -3,8 +3,8 @@ package main
3
  import (
4
  "fmt"
5
 
6
- "go-dp.abdanhafidz.com/config"
7
- "go-dp.abdanhafidz.com/router"
8
  )
9
 
10
  func main() {
 
3
  import (
4
  "fmt"
5
 
6
+ "api.qobiltu.id/config"
7
+ "api.qobiltu.id/router"
8
  )
9
 
10
  func main() {
space/middleware/AuthMiddleware.go CHANGED
@@ -6,10 +6,10 @@ import (
6
  "errors"
7
  "time"
8
 
9
- "github.com/dgrijalva/jwt-go"
 
10
  "github.com/gin-gonic/gin"
11
- "go-dp.abdanhafidz.com/config"
12
- "go-dp.abdanhafidz.com/models"
13
  "golang.org/x/crypto/bcrypt"
14
  )
15
 
@@ -51,8 +51,8 @@ func HashPassword(password string) (string, error) {
51
  }
52
 
53
  type CustomClaims struct {
54
- jwt.StandardClaims
55
- IDUser int `json:"id"`
56
  }
57
 
58
  func VerifyToken(bearer_token string) (int, string, error) {
@@ -63,33 +63,34 @@ func VerifyToken(bearer_token string) (int, string, error) {
63
  if err != nil {
64
  return 0, "invalid-token", err
65
  }
 
 
66
  claims, ok := token.Claims.(*CustomClaims)
67
  if !ok || !token.Valid {
68
  return 0, "invalid-token", err
69
- } else if claims.StandardClaims.ExpiresAt != 0 && claims.ExpiresAt < time.Now().Unix() {
 
70
  return 0, "expired", err
71
- } else if !ok && token.Valid {
72
- return 0, "invalid-token", err
73
  }
74
 
75
- return claims.IDUser, "valid", err
76
  }
77
 
78
  func AuthUser(c *gin.Context) {
79
  var currAccData models.AccountData
80
  if c.Request.Header["Auth-Bearer-Token"] != nil {
81
  token := c.Request.Header["Auth-Bearer-Token"]
82
- currAccData.IdUser, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0])
83
  // fmt.Println("Verify Status :", currAccData.verifyStatus)
84
  if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" {
85
- currAccData.IdUser = 0
86
  message := "Your session is expired, Please re-Login!"
87
  SendJSON401(c, &currAccData.VerifyStatus, &message)
88
  c.Abort()
89
  return
90
  }
91
  } else {
92
- currAccData.IdUser = 0
93
  currAccData.VerifyStatus = "no-token"
94
  currAccData.ErrVerif = nil
95
  message := "You have to Login First!"
 
6
  "errors"
7
  "time"
8
 
9
+ "api.qobiltu.id/config"
10
+ "api.qobiltu.id/models"
11
  "github.com/gin-gonic/gin"
12
+ "github.com/golang-jwt/jwt/v5"
 
13
  "golang.org/x/crypto/bcrypt"
14
  )
15
 
 
51
  }
52
 
53
  type CustomClaims struct {
54
+ jwt.RegisteredClaims
55
+ UserID int `json:"id"`
56
  }
57
 
58
  func VerifyToken(bearer_token string) (int, string, error) {
 
63
  if err != nil {
64
  return 0, "invalid-token", err
65
  }
66
+
67
+ // Extract the claims
68
  claims, ok := token.Claims.(*CustomClaims)
69
  if !ok || !token.Valid {
70
  return 0, "invalid-token", err
71
+ }
72
+ if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) {
73
  return 0, "expired", err
 
 
74
  }
75
 
76
+ return claims.UserID, "valid", err
77
  }
78
 
79
  func AuthUser(c *gin.Context) {
80
  var currAccData models.AccountData
81
  if c.Request.Header["Auth-Bearer-Token"] != nil {
82
  token := c.Request.Header["Auth-Bearer-Token"]
83
+ currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0])
84
  // fmt.Println("Verify Status :", currAccData.verifyStatus)
85
  if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" {
86
+ currAccData.UserID = 0
87
  message := "Your session is expired, Please re-Login!"
88
  SendJSON401(c, &currAccData.VerifyStatus, &message)
89
  c.Abort()
90
  return
91
  }
92
  } else {
93
+ currAccData.UserID = 0
94
  currAccData.VerifyStatus = "no-token"
95
  currAccData.ErrVerif = nil
96
  message := "You have to Login First!"
space/repositories/AccountRepository.go CHANGED
@@ -1,7 +1,7 @@
1
  package repositories
2
 
3
  import (
4
- "go-dp.abdanhafidz.com/models"
5
  )
6
 
7
  func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
 
1
  package repositories
2
 
3
  import (
4
+ "api.qobiltu.id/models"
5
  )
6
 
7
  func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
space/repositories/DatabaseScoope.go CHANGED
@@ -1,5 +1,5 @@
1
  package repositories
2
 
3
- import "go-dp.abdanhafidz.com/config"
4
 
5
  var db = config.DB
 
1
  package repositories
2
 
3
+ import "api.qobiltu.id/config"
4
 
5
  var db = config.DB
space/repositories/repositories.go CHANGED
@@ -1,7 +1,7 @@
1
  package repositories
2
 
3
  import (
4
- "go-dp.abdanhafidz.com/config"
5
  "gorm.io/gorm"
6
  )
7
 
 
1
  package repositories
2
 
3
  import (
4
+ "api.qobiltu.id/config"
5
  "gorm.io/gorm"
6
  )
7
 
space/router/router.go CHANGED
@@ -1,9 +1,9 @@
1
  package router
2
 
3
  import (
 
 
4
  "github.com/gin-gonic/gin"
5
- "go-dp.abdanhafidz.com/config"
6
- "go-dp.abdanhafidz.com/controller"
7
  )
8
 
9
  func StartService() {
 
1
  package router
2
 
3
  import (
4
+ "api.qobiltu.id/config"
5
+ "api.qobiltu.id/controller"
6
  "github.com/gin-gonic/gin"
 
 
7
  )
8
 
9
  func StartService() {
space/services/LoginService.go CHANGED
@@ -3,9 +3,9 @@ package services
3
  import (
4
  "errors"
5
 
6
- "go-dp.abdanhafidz.com/middleware"
7
- "go-dp.abdanhafidz.com/models"
8
- "go-dp.abdanhafidz.com/repositories"
9
  )
10
 
11
  type LoginConstructor struct {
 
3
  import (
4
  "errors"
5
 
6
+ "api.qobiltu.id/middleware"
7
+ "api.qobiltu.id/models"
8
+ "api.qobiltu.id/repositories"
9
  )
10
 
11
  type LoginConstructor struct {
space/services/RegisterService.go CHANGED
@@ -3,10 +3,10 @@ package services
3
  import (
4
  "errors"
5
 
 
 
 
6
  uuid "github.com/satori/go.uuid"
7
- "go-dp.abdanhafidz.com/middleware"
8
- "go-dp.abdanhafidz.com/models"
9
- "go-dp.abdanhafidz.com/repositories"
10
  "gorm.io/gorm"
11
  )
12
 
 
3
  import (
4
  "errors"
5
 
6
+ "api.qobiltu.id/middleware"
7
+ "api.qobiltu.id/models"
8
+ "api.qobiltu.id/repositories"
9
  uuid "github.com/satori/go.uuid"
 
 
 
10
  "gorm.io/gorm"
11
  )
12
 
space/services/services.go CHANGED
@@ -1,6 +1,6 @@
1
  package services
2
 
3
- import "go-dp.abdanhafidz.com/models"
4
 
5
  type (
6
  Services interface {
@@ -21,7 +21,7 @@ type (
21
  )
22
 
23
  func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Service[TConstructor, TResult] {
24
- if len(constructor) == 0 {
25
  return &Service[TConstructor, TResult]{}
26
  }
27
 
 
1
  package services
2
 
3
+ import "api.qobiltu.id/models"
4
 
5
  type (
6
  Services interface {
 
21
  )
22
 
23
  func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Service[TConstructor, TResult] {
24
+ if len(constructor) == 1 {
25
  return &Service[TConstructor, TResult]{}
26
  }
27
 
space/space/models/ExceptionModel.go CHANGED
@@ -1,11 +1,12 @@
1
  package models
2
 
3
  type Exception struct {
4
- Unauthorized bool `json:"unauthorized,omitempty"`
5
- BadRequest bool `json:"bad_request,omitempty"`
6
- DataNotFound bool `json:"data_not_found,omitempty"`
7
- InternalServerError bool `json:"internal_server_error,omitempty"`
8
- DataDuplicate bool `json:"data_duplicate,omitempty"`
9
- QueryError bool `json:"query_error,omitempty"`
10
- Message string `json:"message,omitempty"`
 
11
  }
 
1
  package models
2
 
3
  type Exception struct {
4
+ Unauthorized bool `json:"unauthorized,omitempty"`
5
+ BadRequest bool `json:"bad_request,omitempty"`
6
+ DataNotFound bool `json:"data_not_found,omitempty"`
7
+ InternalServerError bool `json:"internal_server_error,omitempty"`
8
+ DataDuplicate bool `json:"data_duplicate,omitempty"`
9
+ QueryError bool `json:"query_error,omitempty"`
10
+ InvalidPasswordLength bool `json:"invalid_password_length,omitempty"`
11
+ Message string `json:"message,omitempty"`
12
  }
space/space/services/RegisterService.go CHANGED
@@ -15,6 +15,11 @@ type RegisterService struct {
15
  }
16
 
17
  func (s *RegisterService) Create() {
 
 
 
 
 
18
  hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
19
  s.Error = err_hash
20
  s.Constructor.Password = hashed_password
 
15
  }
16
 
17
  func (s *RegisterService) Create() {
18
+ if len(s.Constructor.Password) < 8 {
19
+ s.Exception.InvalidPasswordLength = true
20
+ s.Exception.Message = "Password must have at least 8 characters!"
21
+ return
22
+ }
23
  hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
24
  s.Error = err_hash
25
  s.Constructor.Password = hashed_password
space/space/space/repositories/AccountRepository.go CHANGED
@@ -4,9 +4,9 @@ import (
4
  "go-dp.abdanhafidz.com/models"
5
  )
6
 
7
- func GetAccountbyEmailPassword(email string, password string) Repository[models.Account, models.Account] {
8
  repo := Construct[models.Account, models.Account](
9
- models.Account{Email: email, Password: password},
10
  )
11
  repo.Transactions(
12
  WhereGivenConstructor[models.Account, models.Account],
 
4
  "go-dp.abdanhafidz.com/models"
5
  )
6
 
7
+ func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
8
  repo := Construct[models.Account, models.Account](
9
+ models.Account{Email: email},
10
  )
11
  repo.Transactions(
12
  WhereGivenConstructor[models.Account, models.Account],
space/space/space/repositories/repositories.go CHANGED
@@ -1,8 +1,6 @@
1
  package repositories
2
 
3
  import (
4
- "strconv"
5
-
6
  "go-dp.abdanhafidz.com/config"
7
  "gorm.io/gorm"
8
  )
@@ -51,15 +49,10 @@ func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repo
51
  }
52
  }
53
  func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) {
54
- i := 1
55
  for _, tx := range transactions {
56
  repo.Transaction = tx(repo)
57
  if repo.RowsError != nil {
58
- repo.Transaction.Rollback()
59
  return
60
- } else {
61
- repo.Transaction.SavePoint("Save Point : " + strconv.Itoa(i))
62
- repo.Transaction.Commit()
63
  }
64
  }
65
  }
 
1
  package repositories
2
 
3
  import (
 
 
4
  "go-dp.abdanhafidz.com/config"
5
  "gorm.io/gorm"
6
  )
 
49
  }
50
  }
51
  func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) {
 
52
  for _, tx := range transactions {
53
  repo.Transaction = tx(repo)
54
  if repo.RowsError != nil {
 
55
  return
 
 
 
56
  }
57
  }
58
  }
space/space/space/services/LoginService.go CHANGED
@@ -18,7 +18,7 @@ type AuthenticationService struct {
18
  }
19
 
20
  func (s *AuthenticationService) Authenticate() {
21
- accountData := repositories.GetAccountbyEmailPassword(s.Constructor.Email, s.Constructor.Password)
22
  if accountData.NoRecord {
23
  s.Exception.DataNotFound = true
24
  s.Exception.Message = "there is no account with given credentials!"
 
18
  }
19
 
20
  func (s *AuthenticationService) Authenticate() {
21
+ accountData := repositories.GetAccountbyEmail(s.Constructor.Email)
22
  if accountData.NoRecord {
23
  s.Exception.DataNotFound = true
24
  s.Exception.Message = "there is no account with given credentials!"
space/space/space/services/RegisterService.go CHANGED
@@ -3,6 +3,7 @@ package services
3
  import (
4
  "errors"
5
 
 
6
  "go-dp.abdanhafidz.com/middleware"
7
  "go-dp.abdanhafidz.com/models"
8
  "go-dp.abdanhafidz.com/repositories"
@@ -17,6 +18,7 @@ func (s *RegisterService) Create() {
17
  hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
18
  s.Error = err_hash
19
  s.Constructor.Password = hashed_password
 
20
  accountCreated := repositories.CreateAccount(s.Constructor)
21
  if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
22
  s.Exception.DataDuplicate = true
 
3
  import (
4
  "errors"
5
 
6
+ uuid "github.com/satori/go.uuid"
7
  "go-dp.abdanhafidz.com/middleware"
8
  "go-dp.abdanhafidz.com/models"
9
  "go-dp.abdanhafidz.com/repositories"
 
18
  hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
19
  s.Error = err_hash
20
  s.Constructor.Password = hashed_password
21
+ s.Constructor.UUID = uuid.NewV4()
22
  accountCreated := repositories.CreateAccount(s.Constructor)
23
  if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
24
  s.Exception.DataDuplicate = true
space/space/space/space/go.mod CHANGED
@@ -36,6 +36,7 @@ require (
36
  github.com/modern-go/reflect2 v1.0.2 // indirect
37
  github.com/pelletier/go-toml/v2 v2.1.0 // indirect
38
  github.com/rogpeppe/go-internal v1.11.0 // indirect
 
39
  github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
40
  github.com/ugorji/go/codec v1.2.11 // indirect
41
  golang.org/x/arch v0.6.0 // indirect
 
36
  github.com/modern-go/reflect2 v1.0.2 // indirect
37
  github.com/pelletier/go-toml/v2 v2.1.0 // indirect
38
  github.com/rogpeppe/go-internal v1.11.0 // indirect
39
+ github.com/satori/go.uuid v1.2.0 // indirect
40
  github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
41
  github.com/ugorji/go/codec v1.2.11 // indirect
42
  golang.org/x/arch v0.6.0 // indirect
space/space/space/space/go.sum CHANGED
@@ -79,6 +79,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
79
  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
80
  github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
81
  github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
 
 
82
  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
83
  github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
84
  github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
 
79
  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
80
  github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
81
  github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
82
+ github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
83
+ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
84
  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
85
  github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
86
  github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
space/space/space/space/models/DatabaseModel.go CHANGED
@@ -2,14 +2,18 @@ package models
2
 
3
  import (
4
  "time"
 
 
5
  )
6
 
7
  type Account struct {
8
- Id uint `gorm:"primaryKey" json:"id"`
9
- Email string `gorm:"uniqueIndex" json:"email"`
10
- Password string `json:"password"`
11
- CreatedAt time.Time `json:"created_at"`
12
- DeletedAt time.Time `json:"deleted_at"`
 
 
13
  }
14
 
15
  type AccountDetails struct {
@@ -22,6 +26,14 @@ type AccountDetails struct {
22
  DeletedAt time.Time `json:"deleted_at"`
23
  }
24
 
 
 
 
 
 
 
 
 
25
  // Gorm table name settings
26
  func (Account) TableName() string { return "account" }
27
  func (AccountDetails) TableName() string { return "account_details" }
 
2
 
3
  import (
4
  "time"
5
+
6
+ uuid "github.com/satori/go.uuid"
7
  )
8
 
9
  type Account struct {
10
+ Id uint `gorm:"primaryKey" json:"id"`
11
+ UUID uuid.UUID `gorm:"type:uuid" json:"uuid" `
12
+ Email string `gorm:"uniqueIndex" json:"email"`
13
+ Password string `json:"password"`
14
+ IsEmailVerified bool `json:"is_email_verified"`
15
+ CreatedAt time.Time `json:"created_at"`
16
+ DeletedAt time.Time `json:"deleted_at"`
17
  }
18
 
19
  type AccountDetails struct {
 
26
  DeletedAt time.Time `json:"deleted_at"`
27
  }
28
 
29
+ type EmailVerification struct {
30
+ Id int `gorm:"primaryKey" json:"id"`
31
+ AccountId int `json:"account_id"`
32
+ UUID uuid.UUID `gorm:"type:uuid" json:"uuid" `
33
+ CreatedAt time.Time `json:"created_at"`
34
+ ExpiredAt time.Time `json:"expired_at"`
35
+ }
36
+
37
  // Gorm table name settings
38
  func (Account) TableName() string { return "account" }
39
  func (AccountDetails) TableName() string { return "account_details" }
space/space/space/space/repositories/AccountRepository.go CHANGED
@@ -1,8 +1,6 @@
1
  package repositories
2
 
3
  import (
4
- "fmt"
5
-
6
  "go-dp.abdanhafidz.com/models"
7
  )
8
 
@@ -10,7 +8,6 @@ func GetAccountbyEmailPassword(email string, password string) Repository[models.
10
  repo := Construct[models.Account, models.Account](
11
  models.Account{Email: email, Password: password},
12
  )
13
- fmt.Println(repo.Constructor)
14
  repo.Transactions(
15
  WhereGivenConstructor[models.Account, models.Account],
16
  Find[models.Account, models.Account],
 
1
  package repositories
2
 
3
  import (
 
 
4
  "go-dp.abdanhafidz.com/models"
5
  )
6
 
 
8
  repo := Construct[models.Account, models.Account](
9
  models.Account{Email: email, Password: password},
10
  )
 
11
  repo.Transactions(
12
  WhereGivenConstructor[models.Account, models.Account],
13
  Find[models.Account, models.Account],
space/space/space/space/services/RegisterService.go CHANGED
@@ -14,7 +14,8 @@ type RegisterService struct {
14
  }
15
 
16
  func (s *RegisterService) Create() {
17
- hashed_password, _ := middleware.HashPassword(s.Constructor.Password)
 
18
  s.Constructor.Password = hashed_password
19
  accountCreated := repositories.CreateAccount(s.Constructor)
20
  if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
@@ -26,7 +27,7 @@ func (s *RegisterService) Create() {
26
  s.Exception.Message = "Bad request!"
27
  return
28
  }
29
-
30
  s.Result = accountCreated.Result
31
  s.Result.Password = "SECRET"
32
  }
 
14
  }
15
 
16
  func (s *RegisterService) Create() {
17
+ hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
18
+ s.Error = err_hash
19
  s.Constructor.Password = hashed_password
20
  accountCreated := repositories.CreateAccount(s.Constructor)
21
  if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
 
27
  s.Exception.Message = "Bad request!"
28
  return
29
  }
30
+ s.Error = accountCreated.RowsError
31
  s.Result = accountCreated.Result
32
  s.Result.Password = "SECRET"
33
  }