Giter VIP home page Giter VIP logo

interactor's Introduction

Interactor

Build Status codecov

Interactor is a simple and efficient Go package for managing and dispatching requests to the appropriate use cases according to their request types. It is inspired by Uncle Bob's Clean Architecture and the interactor concept described therein.

The library is designed to be well-documented, thoroughly tested, and easy to use, ensuring maintainable and reliable code for your projects.

Features

  • Dispatcher for managing different use cases.
  • Flexible use cases as either pure functions or structures.
  • Well-documented and tested code.

Installation

To install the Interactor Library, run the following command:

go get -u github.com/screwyprof/interactor/v2

Usage

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/screwyprof/interactor/v2"
)

// TestRequest represents a test request.
type TestRequest struct{}

// TestResponse represents a test response.
type TestResponse struct {
	Result int
}

// UseCase is an example use case implementation.
type UseCase struct {
	Res int
}

// Run runs the use case with the given request.
//
// The response is returned by reference to avoid extra allocations.
func (uc UseCase) Run(ctx context.Context, req TestRequest, res *TestResponse) error {
	res.Result = uc.Res
	return nil
}

func main() {
	// Create a use case.
	useCaseRunner := &UseCase{Res: 42}

	// Create a new dispatcher and register the use case runner.
	dispatcher := interactor.NewDispatcher()
	dispatcher.Register(TestRequest{}, interactor.MustAdapt(useCaseRunner.Run))

	// Run the use case
	var res TestResponse
	if err := dispatcher.Run(context.Background(), TestRequest{}, &res); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("The answer to life, the universe, and everything: %d\n", res.Result)
}

Documentation

For more information and detailed documentation, please refer to the GoDoc documentation:

Interactor Library GoDoc

Contributing

Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open a new issue or submit a pull request.

License

The Interactor Library is released under the MIT License.

interactor's People

Contributors

dependabot[bot] avatar screwyprof avatar

Watchers

 avatar

interactor's Issues

Implement Interactor Library Based on Uncle Bob's Clean Architecture

The goal of this issue is to design and implement a flexible Interactor library for managing use cases, efficiently dispatching requests to the appropriate handlers according to their request types. This library will be based on Uncle Bob's Clean Architecture article and the interactor concept described therein.

The library should define UseCaseRunner interface which will allow to run a use cases. It also should have a Dispatcher which will call a use case for the provided request type.

Task Breakdown:

  1. Define the UseCaseRunner interface.
  2. Implement the Dispatcher.
  3. Ensure both a UseCaseRunner implementation and Dispatcher comply with the same interface.
  4. Write tests to ensure the correct functionality of the Dispatcher and UseCaseRunner.
  5. Add clear and concise comments and documentation throughout the code.
  6. Support flexible implementation of use cases, allowing users to implement use cases as either pure functions or structures.
  7. Use the standard library for implementation, and the testify library for tests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.