code reorganisation
This commit is contained in:
parent
0c75d75e24
commit
133744eb16
8
.gitignore
vendored
8
.gitignore
vendored
@ -22,4 +22,10 @@ go.work
|
|||||||
go.work.sum
|
go.work.sum
|
||||||
|
|
||||||
# env file
|
# env file
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
.run
|
||||||
|
|
||||||
|
# temporary
|
||||||
|
coworker/
|
||||||
|
webapp/
|
||||||
28
main.go
28
main.go
@ -1,15 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/logger"
|
"backend/src/args_parser"
|
||||||
"backend/src/handlers"
|
"backend/src/config"
|
||||||
"backend/src/middleware"
|
"backend/src/core/models"
|
||||||
"backend/src/models"
|
"backend/src/core/repos"
|
||||||
"backend/src/repo"
|
"backend/src/core/services"
|
||||||
"backend/src/services"
|
"backend/src/core/utils"
|
||||||
"backend/src/utils"
|
"backend/src/logger"
|
||||||
"backend/utils/args_parser"
|
"backend/src/server/handlers"
|
||||||
"backend/utils/config"
|
"backend/src/server/middleware"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
@ -75,10 +75,10 @@ func main() {
|
|||||||
|
|
||||||
jwtUtil := utils.NewJwtUtil(key)
|
jwtUtil := utils.NewJwtUtil(key)
|
||||||
passwordUtil := utils.NewPasswordUtil()
|
passwordUtil := utils.NewPasswordUtil()
|
||||||
userRepo := repo.NewUserRepo(sqlDb)
|
userRepo := repos.NewUserRepo(sqlDb)
|
||||||
userCache := repo.NewCacheInmem[string, models.UserDTO](60 * 60)
|
userCache := repos.NewCacheInmem[string, models.UserDTO](60 * 60)
|
||||||
emailRepo := repo.NewEmailRepo()
|
emailRepo := repos.NewEmailRepo()
|
||||||
actionTokenRepo := repo.NewActionTokenRepo(sqlDb)
|
actionTokenRepo := repos.NewActionTokenRepo(sqlDb)
|
||||||
|
|
||||||
userService := services.NewUserService(
|
userService := services.NewUserService(
|
||||||
services.UserServiceDeps{
|
services.UserServiceDeps{
|
||||||
@ -92,7 +92,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
linkService := services.NewShortlinkSevice(
|
linkService := services.NewShortlinkSevice(
|
||||||
services.NewShortlinkServiceParams{
|
services.NewShortlinkServiceParams{
|
||||||
Cache: repo.NewCacheInmem[string, string](7 * 24 * 60 * 60),
|
Cache: repos.NewCacheInmem[string, string](7 * 24 * 60 * 60),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package repo
|
package repos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/src/models"
|
"backend/src/core/models"
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
)
|
)
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package repo
|
package repos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package repo
|
package repos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package repo
|
package repos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/src/models"
|
"backend/src/core/models"
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/src/repo"
|
"backend/src/core/repos"
|
||||||
"backend/src/utils"
|
"backend/src/core/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ type ShortlinkService interface {
|
|||||||
|
|
||||||
type NewShortlinkServiceParams struct {
|
type NewShortlinkServiceParams struct {
|
||||||
Endpoint string
|
Endpoint string
|
||||||
Cache repo.Cache[string, string]
|
Cache repos.Cache[string, string]
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewShortlinkSevice(params NewShortlinkServiceParams) ShortlinkService {
|
func NewShortlinkSevice(params NewShortlinkServiceParams) ShortlinkService {
|
||||||
@ -25,7 +25,7 @@ func NewShortlinkSevice(params NewShortlinkServiceParams) ShortlinkService {
|
|||||||
|
|
||||||
type shortlinkService struct {
|
type shortlinkService struct {
|
||||||
randomUtil utils.RandomUtil
|
randomUtil utils.RandomUtil
|
||||||
cache repo.Cache[string, string]
|
cache repos.Cache[string, string]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *shortlinkService) CreateLink(in string) (string, error) {
|
func (s *shortlinkService) CreateLink(in string) (string, error) {
|
||||||
@ -1,9 +1,9 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/src/models"
|
"backend/src/core/models"
|
||||||
"backend/src/repo"
|
"backend/src/core/repos"
|
||||||
"backend/src/utils"
|
"backend/src/core/utils"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ func NewUserService(deps UserServiceDeps) UserService {
|
|||||||
type UserServiceDeps struct {
|
type UserServiceDeps struct {
|
||||||
Jwt utils.JwtUtil
|
Jwt utils.JwtUtil
|
||||||
Password utils.PasswordUtil
|
Password utils.PasswordUtil
|
||||||
UserRepo repo.UserRepo
|
UserRepo repos.UserRepo
|
||||||
UserCache repo.Cache[string, models.UserDTO]
|
UserCache repos.Cache[string, models.UserDTO]
|
||||||
EmailRepo repo.EmailRepo
|
EmailRepo repos.EmailRepo
|
||||||
ActionTokenRepo repo.ActionTokenRepo
|
ActionTokenRepo repos.ActionTokenRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
type userService struct {
|
type userService struct {
|
||||||
25
src/leader_elector/elector.go
Normal file
25
src/leader_elector/elector.go
Normal 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
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/src/services"
|
"backend/src/core/services"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/src/services"
|
"backend/src/core/services"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/src/services"
|
"backend/src/core/services"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/src/services"
|
"backend/src/core/services"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/logger"
|
"backend/src/logger"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
Loading…
x
Reference in New Issue
Block a user