1 Star 0 Fork 0

暗夜之学/gostudy

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
foobarbaz.go 734 Bytes
一键复制 编辑 原始数据 按行查看 历史
hanjian 提交于 2020-12-28 22:39 +08:00 . ent
package foobarbaz
import (
"context"
"errors"
"github.com/google/wire"
)
// Foo foo
type Foo struct {
X int
}
// ProvideFoo return a Foo
func ProvideFoo() Foo {
return Foo{X: 42}
}
// Bar bar
type Bar struct {
X int
}
// ProvideBar return a Bar: a negative Foo
func ProvideBar(foo Foo) Bar {
return Bar{X: -foo.X}
}
// Baz baz
type Baz struct {
X int
}
// ProvideBaz return a value if Bar is not zero
func ProvideBaz(ctx context.Context, bar Bar) (Baz, error) {
if bar.X == 0 {
return Baz{}, errors.New("cannot provide baz when bar is zero")
}
return Baz{X: bar.X}, nil
}
// SuperSet superset
var SuperSet = wire.NewSet(ProvideFoo, ProvideBar, ProvideBaz)
// MegaSet megaset
var MegaSet = wire.NewSet(SuperSet)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lovehei/gostudy.git
git@gitee.com:lovehei/gostudy.git
lovehei
gostudy
gostudy
73c713180039

搜索帮助