Skip to content

Commit

Permalink
fix di
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed Feb 16, 2024
1 parent 65d75a4 commit c4bbc16
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package custom_handlers
package customhandlers

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package custom_handlers
package customhandlers

import (
"context"
Expand Down
4 changes: 1 addition & 3 deletions internal/app/components/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ var ErrEmptyCommand = errors.New("empty command")
var ErrInvalidCommand = errors.New("invalid command")

var invalidResult = -1
var successResult = 0
var errorResult = 1

type Executor struct {
appendCommandAndExitCode bool
Expand Down Expand Up @@ -76,7 +74,7 @@ func Exec(ctx context.Context, command string, options contracts.ExecutorOptions
return out, exitCode, nil
}

//nolint:lll,funlen
//nolint:funlen
func ExecWithWriter(
ctx context.Context, command string, out io.Writer, options contracts.ExecutorOptions,
) (int, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/app/di/container.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions internal/app/di/internal/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func (c *Container) Error() error {
return c.err
}

// SetError sets the first error into container. The error is used in the public container to return an initialization error.
// SetError sets the first error into container.
// The error is used in the public container to return an initialization error.
func (c *Container) SetError(err error) {
if err != nil && c.err == nil {
c.err = err
Expand All @@ -66,11 +67,11 @@ type RepositoryContainer struct {
serverTaskRepository domain.ServerTaskRepository
}

func (c *Container) Cfg(ctx context.Context) *config.Config {
func (c *Container) Cfg(_ context.Context) *config.Config {
return c.cfg
}

func (c *Container) Logger(ctx context.Context) *logrus.Logger {
func (c *Container) Logger(_ context.Context) *logrus.Logger {
return c.logger
}

Expand Down Expand Up @@ -106,9 +107,9 @@ func (c *ServicesContainer) Resty(ctx context.Context) *resty.Client {
return c.resty
}

func (c *ServicesContainer) ApiCaller(ctx context.Context) contracts.APIRequestMaker {
func (c *ServicesContainer) APICaller(ctx context.Context) contracts.APIRequestMaker {
if c.apiCaller == nil && c.err == nil {
c.apiCaller = definitions.CreateServicesApiCaller(ctx, c)
c.apiCaller = definitions.CreateServicesAPICaller(ctx, c)
}
return c.apiCaller
}
Expand Down Expand Up @@ -175,7 +176,7 @@ func (c *Container) SetLogger(s *logrus.Logger) {
c.logger = s
}

func (c *ServicesContainer) SetApiCaller(s contracts.APIRequestMaker) {
func (c *ServicesContainer) SetAPICaller(s contracts.APIRequestMaker) {
c.apiCaller = s
}

Expand Down
2 changes: 1 addition & 1 deletion internal/app/di/internal/definitions/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func CreateProcessRunner(ctx context.Context, c Container) *services.Runner {
c.Cfg(ctx),
c.Services().Executor(ctx),
c.ServerCommandFactory(ctx),
c.Services().ApiCaller(ctx),
c.Services().APICaller(ctx),
c.Services().GdTaskManager(ctx),
c.Repositories().ServerRepository(ctx),
c.Repositories().ServerTaskRepository(ctx),
Expand Down
2 changes: 1 addition & 1 deletion internal/app/di/internal/definitions/contracts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/app/di/internal/definitions/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

func CreateRepositoriesGdTaskRepository(ctx context.Context, c Container) domain.GDTaskRepository {
return repositories.NewGDTaskRepository(
c.Services().ApiCaller(ctx),
c.Services().APICaller(ctx),
c.Repositories().ServerRepository(ctx),
)
}

func CreateRepositoriesServerRepository(ctx context.Context, c Container) domain.ServerRepository {
return repositories.NewServerRepository(ctx, c.Services().ApiCaller(ctx), c.Logger(ctx))
return repositories.NewServerRepository(ctx, c.Services().APICaller(ctx), c.Logger(ctx))
}

func CreateRepositoriesServerTaskRepository(ctx context.Context, c Container) domain.ServerTaskRepository {
return repositories.NewServerTaskRepository(c.Services().ApiCaller(ctx), c.Repositories().ServerRepository(ctx))
return repositories.NewServerTaskRepository(c.Services().APICaller(ctx), c.Repositories().ServerRepository(ctx))
}
6 changes: 3 additions & 3 deletions internal/app/di/internal/definitions/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/gameap/daemon/internal/app/components"
"github.com/gameap/daemon/internal/app/components/custom_handlers"
"github.com/gameap/daemon/internal/app/components/customhandlers"
"github.com/gameap/daemon/internal/app/contracts"
gdaemonscheduler "github.com/gameap/daemon/internal/app/gdaemon_scheduler"
"github.com/gameap/daemon/internal/app/services"
Expand All @@ -33,7 +33,7 @@ func CreateServicesResty(ctx context.Context, c Container) *resty.Client {
return restyClient
}

func CreateServicesApiCaller(ctx context.Context, c Container) contracts.APIRequestMaker {
func CreateServicesAPICaller(ctx context.Context, c Container) contracts.APIRequestMaker {
client, err := services.NewAPICaller(
ctx,
c.Cfg(ctx),
Expand All @@ -55,7 +55,7 @@ func CreateServicesExecutor(_ context.Context, _ Container) contracts.Executor {
func CreateServiceExtendableExecutor(ctx context.Context, c Container) contracts.Executor {
executor := components.NewDefaultExtendableExecutor(c.Services().Executor(ctx))

executor.RegisterHandler("get-tool", custom_handlers.NewGetTool(c.Cfg(ctx)).Handle)
executor.RegisterHandler("get-tool", customhandlers.NewGetTool(c.Cfg(ctx)).Handle)

return executor
}
Expand Down

0 comments on commit c4bbc16

Please sign in to comment.