if err := store.CompleteWithOptions(options); err != nil {
return nil, err
}
return ®istry.REST{store}, nil
}
它创建了一个名为
genericregistry.Store
的通用注册表对象并设置了一些
字段值。这些字段大多是可选的,如果开发者没有设置它们的值,
store.
CompleteWithOptions
会为它们设置默认值。
从中可以看出是如何在
NewStrategy
构造函数中创建出自定义策略并插入注
册表,实现
create
、
update
和
delete
操作的。
另外,
NewFunc
用于创建新的对象实例,
NewListFunc
用于创建一个对象列表。
PredicateFunc
用于把一个选择器(可以传递给一个列表请求)转换为一个预
测函数,用于过滤运行期的对象。
最终返回的对象是一个
REST
注册表,在我们的示例项目中,它是对通用注
册表对象的一个简单封装,用于创建我们自己的类型:
type REST struct {
*genericregistry.Store
}
有了它就可以开始创建我们的
API
实例,并集成到自定义
API
服务器中了。
在下一节中,我们会学习如何为它创建一个 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.