code reorganisation

This commit is contained in:
Sergey Chubaryan 2024-08-08 19:34:36 +03:00
parent 0c75d75e24
commit 133744eb16
28 changed files with 68 additions and 37 deletions

6
.gitignore vendored
View File

@ -23,3 +23,9 @@ go.work.sum
# env file
.env
.run
# temporary
coworker/
webapp/

28
main.go
View File

@ -1,15 +1,15 @@
package main
import (
"backend/logger"
"backend/src/handlers"
"backend/src/middleware"
"backend/src/models"
"backend/src/repo"
"backend/src/services"
"backend/src/utils"
"backend/utils/args_parser"
"backend/utils/config"
"backend/src/args_parser"
"backend/src/config"
"backend/src/core/models"
"backend/src/core/repos"
"backend/src/core/services"
"backend/src/core/utils"
"backend/src/logger"
"backend/src/server/handlers"
"backend/src/server/middleware"
"crypto/rsa"
"crypto/x509"
"database/sql"
@ -75,10 +75,10 @@ func main() {
jwtUtil := utils.NewJwtUtil(key)
passwordUtil := utils.NewPasswordUtil()
userRepo := repo.NewUserRepo(sqlDb)
userCache := repo.NewCacheInmem[string, models.UserDTO](60 * 60)
emailRepo := repo.NewEmailRepo()
actionTokenRepo := repo.NewActionTokenRepo(sqlDb)
userRepo := repos.NewUserRepo(sqlDb)
userCache := repos.NewCacheInmem[string, models.UserDTO](60 * 60)
emailRepo := repos.NewEmailRepo()
actionTokenRepo := repos.NewActionTokenRepo(sqlDb)
userService := services.NewUserService(
services.UserServiceDeps{
@ -92,7 +92,7 @@ func main() {
)
linkService := services.NewShortlinkSevice(
services.NewShortlinkServiceParams{
Cache: repo.NewCacheInmem[string, string](7 * 24 * 60 * 60),
Cache: repos.NewCacheInmem[string, string](7 * 24 * 60 * 60),
},
)

View File

@ -1,7 +1,7 @@
package repo
package repos
import (
"backend/src/models"
"backend/src/core/models"
"context"
"database/sql"
)

View File

@ -1,4 +1,4 @@
package repo
package repos
import (
"sync"

View File

@ -1,4 +1,4 @@
package repo
package repos
import (
"strings"

View File

@ -1,7 +1,7 @@
package repo
package repos
import (
"backend/src/models"
"backend/src/core/models"
"context"
"database/sql"
"errors"

View File

@ -1,8 +1,8 @@
package services
import (
"backend/src/repo"
"backend/src/utils"
"backend/src/core/repos"
"backend/src/core/utils"
"fmt"
)
@ -13,7 +13,7 @@ type ShortlinkService interface {
type NewShortlinkServiceParams struct {
Endpoint string
Cache repo.Cache[string, string]
Cache repos.Cache[string, string]
}
func NewShortlinkSevice(params NewShortlinkServiceParams) ShortlinkService {
@ -25,7 +25,7 @@ func NewShortlinkSevice(params NewShortlinkServiceParams) ShortlinkService {
type shortlinkService struct {
randomUtil utils.RandomUtil
cache repo.Cache[string, string]
cache repos.Cache[string, string]
}
func (s *shortlinkService) CreateLink(in string) (string, error) {

View File

@ -1,9 +1,9 @@
package services
import (
"backend/src/models"
"backend/src/repo"
"backend/src/utils"
"backend/src/core/models"
"backend/src/core/repos"
"backend/src/core/utils"
"context"
"fmt"
@ -32,10 +32,10 @@ func NewUserService(deps UserServiceDeps) UserService {
type UserServiceDeps struct {
Jwt utils.JwtUtil
Password utils.PasswordUtil
UserRepo repo.UserRepo
UserCache repo.Cache[string, models.UserDTO]
EmailRepo repo.EmailRepo
ActionTokenRepo repo.ActionTokenRepo
UserRepo repos.UserRepo
UserCache repos.Cache[string, models.UserDTO]
EmailRepo repos.EmailRepo
ActionTokenRepo repos.ActionTokenRepo
}
type userService struct {

View File

@ -0,0 +1,25 @@
package leader_elector
import (
"context"
"database/sql"
)
func Lock(ctx context.Context, db *sql.DB, lockName, id string) error {
query := `
update locks (id)
set id = $1
where name == lockName and timestamp < $1 returning id
on conflict
insert into locks(id, name) values($1, $2);`
row := db.QueryRowContext(ctx, query, id)
result := ""
err := row.Scan(&result)
if err != nil {
return err
}
return nil
}

View File

@ -1,7 +1,7 @@
package handlers
import (
"backend/src/services"
"backend/src/core/services"
"encoding/json"
"fmt"
"net/url"

View File

@ -1,7 +1,7 @@
package handlers
import (
"backend/src/services"
"backend/src/core/services"
"encoding/json"
"github.com/gin-gonic/gin"

View File

@ -1,7 +1,7 @@
package handlers
import (
"backend/src/services"
"backend/src/core/services"
"encoding/json"
"github.com/gin-gonic/gin"

View File

@ -1,7 +1,7 @@
package middleware
import (
"backend/src/services"
"backend/src/core/services"
"fmt"
"github.com/gin-gonic/gin"

View File

@ -1,7 +1,7 @@
package middleware
import (
"backend/logger"
"backend/src/logger"
"time"
"github.com/gin-gonic/gin"