本文整理汇总了Golang中github.com/cloudwan/gohan/schema.Schema.IsAbstract方法的典型用法代码示例。如果您正苦于以下问题:Golang Schema.IsAbstract方法的具体用法?Golang Schema.IsAbstract怎么用?Golang Schema.IsAbstract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudwan/gohan/schema.Schema
的用法示例。
在下文中一共展示了Schema.IsAbstract方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetSchema
//GetSchema returns the schema filtered and trimmed for a specific user or nil when the user shouldn't see it at all
func GetSchema(s *schema.Schema, authorization schema.Authorization) (result *schema.Resource, err error) {
manager := schema.GetManager()
metaschema, _ := manager.Schema("schema")
policy, _ := manager.PolicyValidate("read", s.GetPluralURL(), authorization)
if policy == nil {
return
}
if s.IsAbstract() {
return
}
rawSchema := s.JSON()
filteredSchema := util.ExtendMap(nil, s.JSONSchema)
rawSchema["schema"] = filteredSchema
schemaProperties, schemaPropertiesOrder, schemaRequired := policy.FilterSchema(
util.MaybeMap(s.JSONSchema["properties"]),
util.MaybeStringList(s.JSONSchema["propertiesOrder"]),
util.MaybeStringList(s.JSONSchema["required"]))
filteredSchema["properties"] = schemaProperties
filteredSchema["propertiesOrder"] = schemaPropertiesOrder
filteredSchema["required"] = schemaRequired
result, err = schema.NewResource(metaschema, rawSchema)
if err != nil {
log.Warning("%s %s", result, err)
return
}
return
}
示例2: clearTable
func clearTable(tx transaction.Transaction, s *schema.Schema) error {
if s.IsAbstract() {
return nil
}
for _, schema := range schema.GetManager().Schemas() {
if schema.ParentSchema == s {
err := clearTable(tx, schema)
if err != nil {
return err
}
} else {
for _, property := range schema.Properties {
if property.Relation == s.Singular {
err := clearTable(tx, schema)
if err != nil {
return err
}
}
}
}
}
resources, _, err := tx.List(s, nil, nil)
if err != nil {
return err
}
for _, resource := range resources {
err = tx.Delete(s, resource.ID())
if err != nil {
return err
}
}
return nil
}
示例3: DropTable
//DropTable drop table definition
func (db *DB) DropTable(s *schema.Schema) error {
if s.IsAbstract() {
return nil
}
sql := fmt.Sprintf("drop table if exists %s\n", quote(s.GetDbTableName()))
_, err := db.DB.Exec(sql)
return err
}
示例4: RegisterTable
//RegisterTable creates table in the db
func (db *DB) RegisterTable(s *schema.Schema, cascade bool) error {
if s.IsAbstract() {
return nil
}
tableDef, err := db.AlterTableDef(s, cascade)
if err != nil {
tableDef = db.GenTableDef(s, cascade)
}
if tableDef == "" {
return nil
}
_, err = db.DB.Exec(tableDef)
return err
}
示例5: RegisterTable
//RegisterTable creates table in the db
func (db *DB) RegisterTable(s *schema.Schema, cascade bool) error {
if s.IsAbstract() {
return nil
}
tableDef, indices, err := db.AlterTableDef(s, cascade)
if err != nil {
tableDef, indices = db.GenTableDef(s, cascade)
}
if tableDef == "" {
return nil
}
_, err = db.DB.Exec(tableDef)
if err != nil && indices != nil {
for _, indexSql := range indices {
_, err = db.DB.Exec(indexSql)
if err != nil {
return err
}
}
}
return err
}
示例6: MapRouteBySchema
//MapRouteBySchema setup api route by schema
func MapRouteBySchema(server *Server, dataStore db.DB, s *schema.Schema) {
if s.IsAbstract() {
return
}
route := server.martini
singleURL := s.GetSingleURL()
pluralURL := s.GetPluralURL()
singleURLWithParents := s.GetSingleURLWithParents()
pluralURLWithParents := s.GetPluralURLWithParents()
//load extension environments
environmentManager := extension.GetManager()
if _, ok := environmentManager.GetEnvironment(s.ID); !ok {
env, err := server.NewEnvironmentForPath(s.ID, pluralURL)
if err != nil {
log.Fatal(fmt.Sprintf("[%s] %v", pluralURL, err))
}
environmentManager.RegisterEnvironment(s.ID, env)
}
log.Debug("[Plural Path] %s", pluralURL)
log.Debug("[Singular Path] %s", singleURL)
log.Debug("[Plural Path With Parents] %s", pluralURLWithParents)
log.Debug("[Singular Path With Parents] %s", singleURLWithParents)
//setup list route
getPluralFunc := func(w http.ResponseWriter, r *http.Request, p martini.Params, identityService middleware.IdentityService, context middleware.Context) {
addJSONContentTypeHeader(w)
fillInContext(context, dataStore, r, w, s, p, server.sync, identityService, server.queue)
if err := resources.GetMultipleResources(context, dataStore, s, r.URL.Query()); err != nil {
handleError(w, err)
return
}
w.Header().Add("X-Total-Count", fmt.Sprint(context["total"]))
routes.ServeJson(w, context["response"])
}
route.Get(pluralURL, middleware.Authorization(schema.ActionRead), getPluralFunc)
route.Get(pluralURLWithParents, middleware.Authorization(schema.ActionRead), func(w http.ResponseWriter, r *http.Request, p martini.Params, identityService middleware.IdentityService, context middleware.Context) {
addParamToQuery(r, schema.FormatParentID(s.Parent), p[s.Parent])
getPluralFunc(w, r, p, identityService, context)
})
//setup show route
getSingleFunc := func(w http.ResponseWriter, r *http.Request, p martini.Params, identityService middleware.IdentityService, context middleware.Context) {
addJSONContentTypeHeader(w)
fillInContext(context, dataStore, r, w, s, p, server.sync, identityService, server.queue)
id := p["id"]
if err := resources.GetSingleResource(context, dataStore, s, id); err != nil {
handleError(w, err)
return
}
routes.ServeJson(w, context["response"])
}
route.Get(singleURL, middleware.Authorization(schema.ActionRead), getSingleFunc)
route.Get(singleURLWithParents, middleware.Authorization(schema.ActionRead), func(w http.ResponseWriter, r *http.Request, p martini.Params, identityService middleware.IdentityService, context middleware.Context) {
addParamToQuery(r, schema.FormatParentID(s.Parent), p[s.Parent])
getSingleFunc(w, r, p, identityService, context)
})
//setup delete route
deleteSingleFunc := func(w http.ResponseWriter, r *http.Request, p martini.Params, identityService middleware.IdentityService, context middleware.Context) {
addJSONContentTypeHeader(w)
fillInContext(context, dataStore, r, w, s, p, server.sync, identityService, server.queue)
id := p["id"]
if err := resources.DeleteResource(context, dataStore, s, id); err != nil {
handleError(w, err)
return
}
w.WriteHeader(http.StatusNoContent)
}
route.Delete(singleURL, middleware.Authorization(schema.ActionDelete), deleteSingleFunc)
route.Delete(singleURLWithParents, middleware.Authorization(schema.ActionDelete), func(w http.ResponseWriter, r *http.Request, p martini.Params, identityService middleware.IdentityService, context middleware.Context) {
addParamToQuery(r, schema.FormatParentID(s.Parent), p[s.Parent])
deleteSingleFunc(w, r, p, identityService, context)
})
//setup create route
postPluralFunc := func(w http.ResponseWriter, r *http.Request, p martini.Params, identityService middleware.IdentityService, context middleware.Context) {
addJSONContentTypeHeader(w)
fillInContext(context, dataStore, r, w, s, p, server.sync, identityService, server.queue)
dataMap, err := middleware.ReadJSON(r)
if err != nil {
handleError(w, resources.NewResourceError(err, fmt.Sprintf("Failed to parse data: %s", err), resources.WrongData))
return
}
dataMap = removeResourceWrapper(s, dataMap)
if s.Parent != "" {
if _, ok := dataMap[s.ParentID()]; !ok {
queryParams := r.URL.Query()
parentIDParam := queryParams.Get(s.ParentID())
if parentIDParam != "" {
dataMap[s.ParentID()] = parentIDParam
}
}
}
if err := resources.CreateResource(context, dataStore, identityService, s, dataMap); err != nil {
handleError(w, err)
return
//.........这里部分代码省略.........