我有以下简单的设置:
~$ tree
.
??? main.tf
??? modules
??? world
??? main.tf
~$ cat main.tf
output "root_module_says" {
value = "hello from root module"
}
module "world" {
source = "modules/world"
}
~$ cat modules/world/main.tf
output "world_module_says" {
value = "hello from world module"
}
Run Code Online (Sandbox Code Playgroud)
然后我运行:
~$ terraform get
~$ terraform apply
Run Code Online (Sandbox Code Playgroud)
我希望在输出中看到 world_module_says,但我没有,我只看到 root_module_says。这真的很令人困惑,为什么?
如果有帮助:
~$ terraform --version
v0.10.8
Run Code Online (Sandbox Code Playgroud) 包'gopkg.in/redis.v3'包含一些代码
type Client struct {
}
func (*client) Eval (string, []string, []string) *Cmd {
}
type Cmd struct {
}
func (*Cmd) Result () (interface{}, error) {
}
Run Code Online (Sandbox Code Playgroud)
以下列方式成功运作
func myFunc (cli *redis.Client) {
result, err := cli.Eval('my script').Result()
}
Run Code Online (Sandbox Code Playgroud)
问题是,有时候Redis集群会受到重创,有一刻,并且返回的接口结果为零.
这相当容易处理,但我希望进行一项测试,以确保实际处理并且不会发生类型断言恐慌.
传统上我会将一个模拟Redis客户端插入myFunc,最终可以返回nil.
type redisClient interface {
Eval(string, []string, []string) redisCmd
}
type redisCmd interface {
Result() (interface{}, error)
}
func myFunc (cli redisClient) {
result, err := cli.Eval('my script').Result()
}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是编译器无法识别redis.Client满足接口redisClient,因为它无法识别从Eval返回的redis.Cmd满足redisCmd.
> cannot use client (type *redis.Client) as type …Run Code Online (Sandbox Code Playgroud)