diff --git a/cmd/server/main.go b/cmd/server/main.go
index 76cf0c087be14c81404492af02b7c4875d4dd1b9..702ca6e7756dc49c9e23d3a6483a0caada72042b 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -17,12 +17,11 @@ "gorm.io/driver/sqlite"
"gorm.io/gorm"
"git.sr.ht/~gabrielgio/img"
- "git.sr.ht/~gabrielgio/img/pkg/components/auth"
- "git.sr.ht/~gabrielgio/img/pkg/components/filesystem"
"git.sr.ht/~gabrielgio/img/pkg/database/localfs"
"git.sr.ht/~gabrielgio/img/pkg/database/repository"
"git.sr.ht/~gabrielgio/img/pkg/database/sql"
"git.sr.ht/~gabrielgio/img/pkg/ext"
+ "git.sr.ht/~gabrielgio/img/pkg/service"
"git.sr.ht/~gabrielgio/img/pkg/view"
"git.sr.ht/~gabrielgio/img/pkg/worker"
)
@@ -97,8 +96,8 @@ scheduler := worker.NewScheduler(*schedulerCount)
// controller
var (
- userController = auth.NewController(userRepository, userRepository, hexKey)
- fileSystemController = filesystem.NewController(fileSystemRepository)
+ userController = service.NewAuthController(userRepository, userRepository, hexKey)
+ fileSystemController = service.NewFileSystemController(fileSystemRepository)
)
// view
diff --git a/pkg/components/auth/controller.go b/pkg/service/auth.go
rename from pkg/components/auth/controller.go
rename to pkg/service/auth.go
index 0b08fccedac11e0cc5970a746e46432b2390134f..4358a8a6b422a441b85c61c78d13090add66fc84 100644
--- a/pkg/components/auth/controller.go
+++ b/pkg/service/auth.go
@@ -1,34 +1,33 @@
-package auth
+package service
import (
"context"
"golang.org/x/crypto/bcrypt"
- "git.sr.ht/~gabrielgio/img/pkg/components"
"git.sr.ht/~gabrielgio/img/pkg/database/repository"
"git.sr.ht/~gabrielgio/img/pkg/ext"
)
-type Controller struct {
+type AuthController struct {
authRepository repository.AuthRepository
userRepository repository.UserRepository
key []byte
}
-func NewController(
+func NewAuthController(
authRepository repository.AuthRepository,
userRepository repository.UserRepository,
key []byte,
-) *Controller {
- return &Controller{
+) *AuthController {
+ return &AuthController{
authRepository: authRepository,
userRepository: userRepository,
key: key,
}
}
-func (c *Controller) Login(ctx context.Context, username, password []byte) ([]byte, error) {
+func (c *AuthController) Login(ctx context.Context, username, password []byte) ([]byte, error) {
id, err := c.authRepository.GetIDByUsername(ctx, string(username))
if err != nil {
return nil, err
@@ -52,14 +51,14 @@ }
// InitialRegister register a initial user, it will validate if there is another
// user stored already. If so an error `InvlidaInput` will be returned
-func (c *Controller) InitialRegister(ctx context.Context, username, password []byte, path []byte) error {
+func (c *AuthController) InitialRegister(ctx context.Context, username, password []byte, path []byte) error {
exist, err := c.userRepository.Any(ctx)
if err != nil {
return err
}
if exist {
- return components.InvlidaInput
+ return InvlidInput
}
hash, err := bcrypt.GenerateFromPassword(password, bcrypt.MinCost)
diff --git a/pkg/components/auth/controller_test.go b/pkg/service/auth_test.go
rename from pkg/components/auth/controller_test.go
rename to pkg/service/auth_test.go
index b1ca065d481107931ccca4ee3cc48d581472c5f5..35b247575a785ddb5db5c0df0b810c2b6ec08fd8 100644
--- a/pkg/components/auth/controller_test.go
+++ b/pkg/service/auth_test.go
@@ -1,6 +1,6 @@
//go:build unit
-package auth
+package service
import (
"context"
@@ -16,7 +16,7 @@ scene struct {
ctx context.Context
authRepository repository.AuthRepository
userRepository repository.UserRepository
- controller *Controller
+ controller *AuthController
}
)
@@ -30,7 +30,7 @@ return &scene{
ctx: context.Background(),
authRepository: userRepository,
userRepository: userRepository,
- controller: NewController(userRepository, userRepository, key),
+ controller: NewAuthController(userRepository, userRepository, key),
}
}
diff --git a/pkg/components/auth/mock_test.go b/pkg/service/main_test.go
rename from pkg/components/auth/mock_test.go
rename to pkg/service/main_test.go
index 885f64316d474bdf213965a55660ee94fd6bd5b2..5c10ecd7fc5d57b30c8344a2b00354b26cdbbef1 100644
--- a/pkg/components/auth/mock_test.go
+++ b/pkg/service/main_test.go
@@ -1,6 +1,6 @@
//go:build unit
-package auth
+package service
import (
"context"
diff --git a/pkg/components/errors.go b/pkg/components/errors.go
deleted file mode 100644
index aedbe889b5f1e2d54616f746b859da359a288be5..0000000000000000000000000000000000000000
--- a/pkg/components/errors.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package components
-
-import "errors"
-
-var (
- NotFound = errors.New("Not found")
- InvlidaInput = errors.New("Invalid Input")
-)
diff --git a/pkg/components/filesystem/controller.go b/pkg/service/filesystem.go
rename from pkg/components/filesystem/controller.go
rename to pkg/service/filesystem.go
index 6c613a3c0c1e1cd8ba152e855deeb12e8fb2b1a3..3516ce2642ba63e2d8ef7f774469657d64123c70 100644
--- a/pkg/components/filesystem/controller.go
+++ b/pkg/service/filesystem.go
@@ -1,4 +1,4 @@
-package filesystem
+package service
import (
"io/fs"
@@ -10,7 +10,7 @@ "git.sr.ht/~gabrielgio/img/pkg/database/repository"
)
type (
- Controller struct {
+ FileSystemController struct {
repository repository.FileSystemRepository
}
@@ -30,8 +30,8 @@ Files []*FileParam
}
)
-func NewController(repository repository.FileSystemRepository) *Controller {
- return &Controller{
+func NewFileSystemController(repository repository.FileSystemRepository) *FileSystemController {
+ return &FileSystemController{
repository: repository,
}
}
@@ -63,7 +63,7 @@ }
return result
}
-func (self *Controller) GetPage(filepath string) (*Page, error) {
+func (self *FileSystemController) GetPage(filepath string) (*Page, error) {
decodedPath, err := url.QueryUnescape(filepath)
if err != nil {
return nil, err
diff --git a/pkg/components/user/controller.go b/pkg/components/user/controller.go
deleted file mode 100644
index a00006b65468ecad731002a1e2c54884759656ed..0000000000000000000000000000000000000000
--- a/pkg/components/user/controller.go
+++ /dev/null
@@ -1 +0,0 @@
-package user
diff --git a/pkg/service/errors.go b/pkg/service/errors.go
new file mode 100644
index 0000000000000000000000000000000000000000..65984642e7efd0eb0b975777cc4a4a942fadd207
--- /dev/null
+++ b/pkg/service/errors.go
@@ -0,0 +1,8 @@
+package service
+
+import "errors"
+
+var (
+ NotFound = errors.New("Not found")
+ InvlidInput = errors.New("Invalid Input")
+)
diff --git a/pkg/view/auth.go b/pkg/view/auth.go
index 3f9e4140365dbed89f490c6d39e066670fc3d1b4..6b096d9ff553f6d8329eacf7265142696db11d4b 100644
--- a/pkg/view/auth.go
+++ b/pkg/view/auth.go
@@ -6,15 +6,15 @@
"github.com/valyala/fasthttp"
"git.sr.ht/~gabrielgio/img"
- "git.sr.ht/~gabrielgio/img/pkg/components/auth"
"git.sr.ht/~gabrielgio/img/pkg/ext"
+ "git.sr.ht/~gabrielgio/img/pkg/service"
)
type AuthView struct {
- userController *auth.Controller
+ userController *service.AuthController
}
-func NewAuthView(userController *auth.Controller) *AuthView {
+func NewAuthView(userController *service.AuthController) *AuthView {
return &AuthView{
userController: userController,
}
diff --git a/pkg/view/filesystem.go b/pkg/view/filesystem.go
index d2ebff41d46fb2a9cb581d29ee31bca4af814216..d598b88014738c96532ea5b265f804ac9f87fcf2 100644
--- a/pkg/view/filesystem.go
+++ b/pkg/view/filesystem.go
@@ -4,25 +4,25 @@ import (
"github.com/valyala/fasthttp"
"git.sr.ht/~gabrielgio/img"
- "git.sr.ht/~gabrielgio/img/pkg/components/filesystem"
"git.sr.ht/~gabrielgio/img/pkg/database/repository"
"git.sr.ht/~gabrielgio/img/pkg/ext"
+ "git.sr.ht/~gabrielgio/img/pkg/service"
)
type (
FileSystemView struct {
- controller filesystem.Controller
+ controller service.FileSystemController
settings repository.SettingsRepository
}
FilePage struct {
- Page *filesystem.Page
+ Page *service.Page
ShowMode bool
ShowOwner bool
}
)
func NewFileSystemView(
- controller filesystem.Controller,
+ controller service.FileSystemController,
settingsRepository repository.SettingsRepository,
) *FileSystemView {
return &FileSystemView{