refactor(service): use service as struct instead of interface
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
type router struct {
|
||||
service service.Service
|
||||
service *service.Service
|
||||
|
||||
templates *template.Template
|
||||
staticFiles fs.FS
|
||||
@@ -43,6 +43,8 @@ func New(cfg Config) (http.Handler, error) {
|
||||
}
|
||||
|
||||
r := &router{
|
||||
service: cfg.Service,
|
||||
|
||||
templates: cfg.Templates,
|
||||
staticFiles: cfg.StaticFiles,
|
||||
|
||||
@@ -55,7 +57,7 @@ func New(cfg Config) (http.Handler, error) {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Service service.Service
|
||||
Service *service.Service
|
||||
|
||||
Templates *template.Template
|
||||
StaticFiles fs.FS
|
||||
|
||||
@@ -10,8 +10,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
s3 *s3.Client
|
||||
type Service struct {
|
||||
db *database.Database
|
||||
|
||||
ctx context.Context
|
||||
@@ -20,7 +19,7 @@ type service struct {
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func New(cfg Config) (Service, error) {
|
||||
func New(cfg Config) (*Service, error) {
|
||||
if cfg.DB == nil {
|
||||
return nil, errors.New("database should not be a nil pointer")
|
||||
}
|
||||
@@ -36,8 +35,8 @@ func New(cfg Config) (Service, error) {
|
||||
if cfg.Logger == nil {
|
||||
return nil, errors.New("logger should not be a nil pointer")
|
||||
}
|
||||
return &service{
|
||||
db: cfg.DB,
|
||||
return &Service{
|
||||
|
||||
ctx: cfg.Context,
|
||||
|
||||
@@ -55,8 +54,3 @@ type Config struct {
|
||||
Assertions tinyssert.Assertions
|
||||
Logger *slog.Logger
|
||||
}
|
||||
|
||||
type Service interface {
|
||||
ListProjects()
|
||||
NewProject()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user