私人[路线]是什么意思?
What does private[routes] mean?
我有以下代码片段:
final class UserRoutes[F[_]: Defer: JsonDecoder: MonadThrow](
auth: Auth[F]
) extends Http4sDsl[F] {
private[routes] val prefixPath = "/auth"
private val httpRoutes: HttpRoutes[F] =
HttpRoutes.of[F] {
case req @ POST -> Root / "users" =>
req
.decodeR[CreateUser] { user =>
auth
.newUser(
user.username.toDomain,
user.password.toDomain
)
.flatMap(Created(_))
.recoverWith {
case UserNameInUse(u) =>
Conflict(u.value)
}
}
}
val routes: HttpRoutes[F] = Router(
prefixPath -> httpRoutes
)
}
我不明白表达式private[routes] val prefixPath = "/auth"
的意思。谁能解释一下表达式的含义?
这意味着 prefixPath
成员只能在 UserRoutes
上从 routes
包中访问。
我有以下代码片段:
final class UserRoutes[F[_]: Defer: JsonDecoder: MonadThrow](
auth: Auth[F]
) extends Http4sDsl[F] {
private[routes] val prefixPath = "/auth"
private val httpRoutes: HttpRoutes[F] =
HttpRoutes.of[F] {
case req @ POST -> Root / "users" =>
req
.decodeR[CreateUser] { user =>
auth
.newUser(
user.username.toDomain,
user.password.toDomain
)
.flatMap(Created(_))
.recoverWith {
case UserNameInUse(u) =>
Conflict(u.value)
}
}
}
val routes: HttpRoutes[F] = Router(
prefixPath -> httpRoutes
)
}
我不明白表达式private[routes] val prefixPath = "/auth"
的意思。谁能解释一下表达式的含义?
这意味着 prefixPath
成员只能在 UserRoutes
上从 routes
包中访问。