Skip to content

Conversation

@jh125486
Copy link

So this PR is really two things (sorry):

  1. renaming all interface{} -> any and ioutil deprecations (lots of files changes)
  2. Usecase interactor hooks (nethttp/handler.go and associated test file)

My original intention was to just do the Usecase hooks, but the linter got the best of me :/

Anyways.... I have a need for running hooks after input is processed/validated but before the usecase is run (and the same for after the usecase is run, but before the output is validated).
It's a slice of function hooks, that are called before and after useCase.Interact() is called at nethttp/handler.go:135.

Updated deprecated calls
Updated golangci rules
Updated to Go1.18 `any`
Added Hooks around UseCase Interactor execution
@vearutop
Copy link
Member

I'm sorry it took me so long to review this PR (it would be easier without cosmetic changes).

It seems the same functionality can be achieved with already existing usecase middlewares.

Here is an example

	s := web.DefaultService()
	s.Wrap(nethttp.UseCaseMiddlewares(usecase.MiddlewareFunc(func(next usecase.Interactor) usecase.Interactor {
		var (
			hasName usecase.HasName
			name    = "unknown"
		)

		if usecase.As(next, &hasName) {
			name = hasName.Name()
		}

		return usecase.Interact(func(ctx context.Context, input, output interface{}) error {
			err := next.Interact(ctx, input, output)
			if err != nil {
				log.Printf("usecase %s request (%v) failed: %v\n", name, input, err)
			}

			return err
		})
	})))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants