Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduces boilerplate when creating client instances #97

Merged
merged 1 commit into from
Dec 18, 2017

Conversation

juanpedromoreno
Copy link
Member

This PR reduces some boilerplate when creating RPC client instances:

Previously to this change, in order to create new client instances, users have to do something like the following:

import cats.effect.IO
import freestyle.rpc.client._
import io.grpc.ManagedChannel //notice a io.grpc.import

val channelFor: ManagedChannelFor = ManagedChannelForAddress("localhost", 8080)

val channelConfigList: List[ManagedChannelConfig] = List(UsePlaintext(true))

val managedChannelInterpreter =
  new ManagedChannelInterpreter[IO](channelFor, channelConfigList)

val channel: ManagedChannel = managedChannelInterpreter.build(channelFor, channelConfigList)

val client: YourService.Client[IO] = YourService.client[IO](channel)

After this change, channelConfigList would be optional since it has a default value: _ = List(UsePlaintext(true)). Additionally, clients won't receive a io.grpc.ManagedChannel as first argument anymore, instead it'll receive the ManagedChannelFor object. Hence, this would be the equivalent version of the code above:

val channelFor: ManagedChannelFor = ManagedChannelForAddress("localhost", 8080)
val client: YourService.Client[IO] = YourService.client[IO](channelFor)

Optionally, as we've mentioned, you could still pass a List[ManagedChannelConfig] as a second argument.

@codecov-io
Copy link

Codecov Report

Merging #97 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #97   +/-   ##
=======================================
  Coverage   83.21%   83.21%           
=======================================
  Files          12       12           
  Lines         137      137           
=======================================
  Hits          114      114           
  Misses         23       23

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c65515c...5c14ffc. Read the comment docs.

Copy link
Contributor

@fedefernandez fedefernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!
giphy

@juanpedromoreno juanpedromoreno merged commit 4597dfc into master Dec 18, 2017
@juanpedromoreno juanpedromoreno deleted the jp-reduces-boilerplate-for-clients branch December 18, 2017 09:16
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