本文整理匯總了Golang中github.com/app-kit/go-appkit.Resource.SetBackend方法的典型用法代碼示例。如果您正苦於以下問題:Golang Resource.SetBackend方法的具體用法?Golang Resource.SetBackend怎麽用?Golang Resource.SetBackend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/app-kit/go-appkit.Resource
的用法示例。
在下文中一共展示了Resource.SetBackend方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RegisterResource
func (s *Service) RegisterResource(res kit.Resource) {
if res.Backend() == nil {
if s.defaultBackend == nil {
s.registry.Logger().Panic("Registering resource without backend, but no default backend set on resources.Service")
}
s.defaultBackend.RegisterModel(res.Model())
res.SetBackend(s.defaultBackend)
}
if res.Collection() == "" {
s.registry.Logger().Panic("Registering resource without a model type")
}
s.resources[res.Collection()] = res
}
示例2: RegisterResource
func (a *App) RegisterResource(res kit.Resource) {
if res.Backend() == nil {
if a.registry.DefaultBackend() == nil {
a.Logger().Panic("Registering resource without backend, but no default backend set.")
}
// Set backend.
res.SetBackend(a.registry.DefaultBackend())
}
if res.Registry() == nil {
res.SetRegistry(a.registry)
}
res.SetDebug(a.Debug())
// Allow a resource to register custom http routes and methods.
if res.Hooks() != nil {
// Handle http routes.
if resRoutes, ok := res.Hooks().(resources.ApiHttpRoutes); ok {
for _, route := range resRoutes.HttpRoutes(res) {
a.RegisterHttpHandler(route.Method(), route.Route(), route.Handler())
}
}
// Handle methods.
if resMethods, ok := res.Hooks().(resources.MethodsHook); ok {
for _, method := range resMethods.Methods(res) {
a.RegisterMethod(method)
}
}
}
a.registry.AddResource(res)
}