- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 Finch 和 Finagle 制作了一个非常简单的休息方法:
val getUsers:Endpoint[List[User]] = get("users") {Ok(getAllUsers())}
Http.serve(":8080", getUsers.toService)
并收到此错误:
Error:(50, 32) not enough arguments for method toService: (implicit ts: io.finch.internal.ToService[List[DAL.Instances.User.User]])com.twitter.finagle.Service[com.twitter.finagle.http.Request,com.twitter.finagle.http.Response].
Unspecified value parameter ts.
Http.serve(":8080", getUsers.toService)
^
知道如何解决这个问题吗?
最佳答案
最新版本的 Finch (0.10) 中的编译器错误情况有所改善。如果我们有以下构建配置:
scalaVersion := "2.11.7"
libraryDependencies += "com.github.finagle" %% "finch-core" % "0.10.0"
这个设置:
import com.twitter.finagle.Http
import io.finch._
case class User(id: String, name: String)
def getAllUsers(): List[User] = List(User("111", "Foo McBar"))
val getUsers: Endpoint[List[User]] = get("users") { Ok(getAllUsers()) }
然后,当我们尝试使用 toService
时,我们得到以下结果:
<console>:18: error: You can only convert a router into a Finagle service if the
result type of the router is one of the following:
* A Response
* A value of a type with an EncodeResponse instance
* A coproduct made up of some combination of the above
List[User] does not satisfy the requirement. You may need to provide an
EncodeResponse instance for List[User] (or for some part of List[User]).
Http.serve(":8080", getUsers.toService)
^
问题是您没有告诉 Finch 如何将您的 User
类型的实例转换为 HTTP 响应。 Finch 的 EncodeResponse
是 type class 的一个示例,这是一种多态性方法,广泛用于 Scala(包括标准库)和许多其他静态类型函数编程语言。
提供适当 EncodeResponse
实例的最简单方法是添加 Finch 的 Circe您的构建的兼容性模块:
libraryDependencies ++= Seq(
"io.circe" %% "circe-generic" % "0.3.0",
"com.github.finagle" %% "finch-circe" % "0.10.0"
)
然后您所需要的只是以下导入:
import io.finch.circe._, io.circe.generic.auto._
并且 toService
会正常工作:
scala> Http.serve(":8080", getUsers.toService)
Feb 26, 2016 8:32:24 AM com.twitter.finagle.Init$$anonfun$1 apply$mcV$sp
INFO: Finagle version 6.33.0 (rev=21d0ee8b5070b735eda5c84d7aa6fbf1ba7b1635) built at 20160203-202859
res2: com.twitter.finagle.ListeningServer = Group(/0:0:0:0:0:0:0:0:8080)
现在,如果您访问 http://localhost:8080/users
,您将看到以下内容:
[{"id":"111","name":"Foo McBar"}]
这看起来很神奇,但所发生的事情是相当有原则的。 Circe是一个 JSON 库,提供通用编解码器派生,可在编译时确定如何将案例类表示为 JSON 值(有关更多上下文,请参阅我的博客文章 here)。
Finch cookbook是了解有关此类问题的更多信息的绝佳资源,第一部分详细介绍了提供 toService
所需的 EncoderResponse
实例的其他方法。如果您还有任何其他问题或上述任何疑问,请随时在此处或通过 Gitter 提问。 .
关于scala - Finch:方法 'toService' 的参数不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35646410/
所以我正在为考试复习,并在 SQL 河(或荒地)中撞到了一块大石头 我制作了以下表格并插入了以下数据: create table Permissions ( fileName VARCHAR(
我有一个使用 maxWidth 定义的 jqueryui 对话框。 $("#myDialog").dialog({ autoOpen: false, width: 'a
注意:我遗漏了不相关的代码 所以我目前正在研究 CCC 1996 P1,这个问题的全部目的是能够计算一个整数输入是完美数、不足数还是充数。我上面列出的代码可以工作,但是我认为它太慢了。该代码会迭代每个
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在使用 Go 和 Redis 开发 API。问题是RAM使用不足,我找不到问题的根源。 TL;DR 版本 有数百/数千个哈希对象。每个 1 KB 的对象(键+值)占用大约 0.5 MB 的 RAM
在我的 GCE Kubernetes 集群上,我无法再创建 pod。 Warning FailedScheduling pod (www.caveconditions.com-f1be467e3
当我尝试在EKS Fargate群集上安装指标服务器时,它抛出错误: 0/4 nodes are available: 4 Insufficient pods. 按照以下说明从此处安装指标服务器:ht
遍布this document Apple 提到 iOS 在某些情况下会终止应用程序,最常见的原因似乎是释放一些 RAM。这会导致未实现状态恢复的应用程序出现问题——用户正在处理和暂时离开的一些内容可
尝试处理一个10分钟的音频文件时出现以下错误。我刚刚开始使用Google Cloud产品,所以我是唯一访问此资源的人。我怎么可能超出配额?配额设置为其默认值,我认为我没有任何限制。还有其他原因吗? 我
R 语言让我感到困惑。实体有模式和类,但即使这样也不足以完全描述实体。 这个answer说 In R every 'object' has a mode and a class. 所以我做了这些实验:
我在 west-1 有一个 Openshift v3 项目。在其中,我有一个运行良好的应用程序,但在 GitHub 提交代码中非常下游的内容后,该应用程序停止工作。问题在于制作 pod: No nod
我在 west-1 有一个 Openshift v3 项目。在其中,我有一个运行良好的应用程序,但在 GitHub 提交代码中非常下游的内容后,该应用程序停止工作。问题在于制作 pod: No nod
在 how-do-i-access-the-stackoverflow-api-from-mathematica我概述了如何使用 SO API 让 Mathematica 制作一些有趣的顶级回答者声誉
所以在 GKE 上,我有一个 Node.js app,每个 pod 使用大约:CPU(cores): 5m, MEMORY: 100Mi 但是我只能为每个 Node 部署 1 个 pod。我使用的是
我正在使用 async.eachOfSeries 超过 300 个数组并请求一些 GA api,它工作正常但有时我会收到错误.. UnhandledPromiseRejectionWarning:错误
我正在尝试在 AWS ec2 上托管的 kubernetes 集群上使用 mr3 设置配置单元。当我运行命令 run-hive.sh 时,Hive 服务器启动,并且 master-DAg 被初始化,但
创建订阅时有时会出现以下错误: Insufficient tokens for quota 'administrator' and limit 'CLIENT_PROJECT-100s' of ser
我是一名优秀的程序员,十分优秀!