Sign inSign up

csueiras/reinforcer

By csueiras

•Updated over 5 years ago

A codegen tool for easy adoption of resiliency patterns

Image
0

1.5K

csueiras/reinforcer repository overview

⁠reinforcer

Tests Coverage Status Go Report Card GitHub tag (latest SemVer pre-release) License: MIT

Reinforcer is a code generation tool that automates middleware injection in a proxy service that fronts your delegate implementation, this aids in building more resilient code as you can use common resiliency patterns in the middlewares such as circuit breakers, retrying, timeouts and others.

NOTE: This tool is under heavy development, not yet recommended for production use.

⁠Install

⁠Releases

Visit the releases page⁠ for pre-built binaries for OS X, Linux and Windows.

⁠Docker

Use the Docker Image⁠:

docker pull csueiras/reinforcer
⁠Homebrew

Install through Homebrew⁠

brew tap csueiras/reinforcer && brew install reinforcer

⁠Usage

  1. Describe the target that you want to generate code for:
type Client interface {
	DoOperation(ctx context.Context, arg string) error
}
  1. Create the runner/middleware factory with the middlewares you want to inject into the generated code:
r := runner.NewFactory(
    metrics.NewMiddleware(...),
    circuitbreaker.NewMiddleware(...),
    bulkhead.NewMiddleware(...),
    retry.NewMiddleware(...),
    timeout.NewMiddleware(...),
)
  1. Optionally create your predicate for errors that shouldn't be retried
errPredicate := func(method string, err error) bool {
    if method == "DoOperation" && errors.Is(client.NotFound, err) {
        return false
    }
    return true
}
  1. Wrap the "real"/unrealiable implementation in the generated code:
c := client.NewClient(...)

// reinforcedClient implements the target interface so it can now be used in lieau of any place where the unreliable
// client was used
reinforcedClient := reinforced.NewClient(c, r, reinforced.WithRetryableErrorPredicate(errPredicate))

A complete example is here⁠

Tag summary

Content type

Image

Digest

Size

109.4 MB

Last updated

over 5 years ago

docker pull csueiras/reinforcer