-
Notifications
You must be signed in to change notification settings - Fork 34
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
Decouple frees config #300
Conversation
depend on pureconfig instead
create our own ConfigM instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Could you update the docs accordingly? The code samples are executed via tut
and are currently failing the build (https://travis-ci.org/frees-io/freestyle-rpc/jobs/388386394). Thanks!
def apply[F[_]](implicit S: Sync[F], C: ConfigM[F]): ChannelConfig[F] = new ChannelConfig[F] { | ||
def sync = S | ||
def configM = C | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest the following approach, more natural perhaps?
class ChannelConfig[F[_]](implicit S: Sync[F], C: ConfigM[F]) {
val defaultHost: String = "localhost"
val defaultPort: Int = freestyle.rpc.server.defaultPort
def loadChannelAddress(hostPath: String, portPath: String): F[ChannelForAddress] =
for {
config <- C.load
host <- S.pure(
Either
.catchOnly[Missing](config.getString(hostPath)))
port <- S.pure(Either.catchOnly[Missing](config.getInt(portPath)))
} yield ChannelForAddress(host.getOrElse(defaultHost), port.getOrElse(defaultPort))
def loadChannelTarget(targetPath: String): F[ChannelForTarget] =
for {
config <- C.load
target <- S.pure(Either.catchOnly[Missing](config.getString(targetPath)))
} yield ChannelForTarget(target.getOrElse("target"))
}
object ChannelConfig {
def apply[F[_]](implicit S: Sync[F], C: ConfigM[F]): ChannelConfig[F] = new ChannelConfig[F]
implicit def defaultChannelConfig[F[_]](implicit S: Sync[F], C: ConfigM[F]): ChannelConfig[F] =
apply[F]
}
trait ServerConfig { | ||
trait ServerConfig[F[_]] { | ||
|
||
implicit def sync: Sync[F] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, I've left an optional suggestion. Thanks
|
||
trait ConfigM[F[_]] { | ||
def load: F[Config] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we could add a new method to this algebra:
def get[A](from: (Config) => A): F[Either[Missing, A]]
With the implementation:
def get[A](getValue: => A): F[Either[Missing, A]] =
S.pure(Either.catchOnly[Missing](getValue))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that, at some point in the near future, we'll reintroduce frees-config
, and we could maybe add it there? this implementation is temporary. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
In this PR I:
ConfigM
tagless to be used whereverfreestyle.tagless.config
were used before@module
annotationsfrees-todolist-lib
tov0.8.1
0.3.23
FIXES #294