本文整理汇总了Golang中github.com/solher/zest/usecases.NewDirectoryKey函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDirectoryKey函数的具体用法?Golang NewDirectoryKey怎么用?Golang NewDirectoryKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDirectoryKey函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RelatedOne
func (c *AclCtrl) RelatedOne(w http.ResponseWriter, r *http.Request, params map[string]string) {
pk, err := strconv.Atoi(params["pk"])
if err != nil {
c.render.JSONError(w, http.StatusBadRequest, apierrors.InvalidPathParams, err)
return
}
params["id"] = params["fk"]
related := params["related"]
key := usecases.NewDirectoryKey(related)
var handler usecases.HandlerFunc
switch r.Method {
case "GET":
handler = c.routeDir.Get(key.For("FindByID")).EffectiveHandler
case "DELETE":
handler = c.routeDir.Get(key.For("DeleteByID")).EffectiveHandler
}
if handler == nil {
c.render.JSON(w, http.StatusNotFound, nil)
return
}
context.Set(r, "lastRessource", &interfaces.Ressource{Name: related, IDKey: "aclID", ID: pk})
handler(w, r, params)
}
示例2: setAccountRoutes
func setAccountRoutes(routeDir *usecases.RouteDirectory, controller *AccountCtrl) {
key := usecases.NewDirectoryKey("accounts")
routeDir.Add(key.For("Signin"), &usecases.Route{Method: "POST", Path: "/accounts/signin", Handler: controller.Signin, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("Signout"), &usecases.Route{Method: "POST", Path: "/accounts/signout", Handler: controller.Signout, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("Signup"), &usecases.Route{Method: "POST", Path: "/accounts/signup", Handler: controller.Signup, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("Current"), &usecases.Route{Method: "GET", Path: "/accounts/me", Handler: controller.Current, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("DeleteCurrent"), &usecases.Route{Method: "DELETE", Path: "/accounts/me", Handler: controller.DeleteCurrent, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("Create"), &usecases.Route{Method: "POST", Path: "/accounts", Handler: controller.Create, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("Find"), &usecases.Route{Method: "GET", Path: "/accounts", Handler: controller.Find, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("FindByID"), &usecases.Route{Method: "GET", Path: "/accounts/:id", Handler: controller.FindByID, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("Upsert"), &usecases.Route{Method: "PUT", Path: "/accounts", Handler: controller.Upsert, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("UpdateByID"), &usecases.Route{Method: "PUT", Path: "/accounts/:id", Handler: controller.UpdateByID, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("DeleteAll"), &usecases.Route{Method: "DELETE", Path: "/accounts", Handler: controller.DeleteAll, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("DeleteByID"), &usecases.Route{Method: "DELETE", Path: "/accounts/:id", Handler: controller.DeleteByID, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("UpdatePasswordRelated"), &usecases.Route{Method: "POST", Path: "/accounts/:pk/users/:fk/updatePassword", Handler: controller.UpdatePasswordRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("CreateRelated"), &usecases.Route{Method: "POST", Path: "/accounts/:pk/:related", Handler: controller.CreateRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("FindRelated"), &usecases.Route{Method: "GET", Path: "/accounts/:pk/:related", Handler: controller.FindRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("FindByIDRelated"), &usecases.Route{Method: "GET", Path: "/accounts/:pk/:related/:fk", Handler: controller.FindByIDRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("UpsertRelated"), &usecases.Route{Method: "PUT", Path: "/accounts/:pk/:related", Handler: controller.UpsertRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("UpdateByIDRelated"), &usecases.Route{Method: "PUT", Path: "/accounts/:pk/:related/:fk", Handler: controller.UpdateByIDRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("DeleteAllRelated"), &usecases.Route{Method: "DELETE", Path: "/accounts/:pk/:related", Handler: controller.DeleteAllRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("DeleteByIDRelated"), &usecases.Route{Method: "DELETE", Path: "/accounts/:pk/:related/:fk", Handler: controller.DeleteByIDRelated, Visible: true, CheckPermissions: false})
}
示例3: RelatedOne
func (c *AccountCtrl) RelatedOne(w http.ResponseWriter, r *http.Request, params map[string]string) {
var (
pk int
err error
)
if params["pk"] == "me" {
sessionCtx := context.Get(r, "currentSession")
if sessionCtx == nil {
c.render.JSONError(w, http.StatusUnauthorized, apierrors.SessionNotFound, nil)
return
}
pk = sessionCtx.(domain.Session).AccountID
} else {
pk, err = strconv.Atoi(params["pk"])
if err != nil {
c.render.JSONError(w, http.StatusBadRequest, apierrors.InvalidPathParams, err)
return
}
}
params["id"] = params["fk"]
related := params["related"]
key := usecases.NewDirectoryKey(related)
var handler usecases.HandlerFunc
switch r.Method {
case "GET":
handler = c.routeDir.Get(key.For("FindByID")).EffectiveHandler
case "DELETE":
handler = c.routeDir.Get(key.For("DeleteByID")).EffectiveHandler
case "PUT":
handler = c.routeDir.Get(key.For("UpdateByID")).EffectiveHandler
}
if handler == nil {
c.render.JSON(w, http.StatusNotFound, nil)
return
}
context.Set(r, "lastRessource", &interfaces.Ressource{Name: related, IDKey: "accountID", ID: pk})
handler(w, r, params)
}
示例4: setAclRoutes
func setAclRoutes(routeDir *usecases.RouteDirectory, controller *AclCtrl) {
key := usecases.NewDirectoryKey("acls")
routeDir.Add(key.For("Create"), &usecases.Route{Method: "POST", Path: "/acls", Handler: controller.Create, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("Find"), &usecases.Route{Method: "GET", Path: "/acls", Handler: controller.Find, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("FindByID"), &usecases.Route{Method: "GET", Path: "/acls/:id", Handler: controller.FindByID, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("Upsert"), &usecases.Route{Method: "PUT", Path: "/acls", Handler: controller.Upsert, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("UpdateByID"), &usecases.Route{Method: "PUT", Path: "/acls/:id", Handler: controller.UpdateByID, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("DeleteAll"), &usecases.Route{Method: "DELETE", Path: "/acls", Handler: controller.DeleteAll, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("DeleteByID"), &usecases.Route{Method: "DELETE", Path: "/acls/:id", Handler: controller.DeleteByID, Visible: true, CheckPermissions: true})
routeDir.Add(key.For("CreateRelated"), &usecases.Route{Method: "POST", Path: "/acls/:pk/:related", Handler: controller.CreateRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("FindRelated"), &usecases.Route{Method: "GET", Path: "/acls/:pk/:related", Handler: controller.FindRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("FindByIDRelated"), &usecases.Route{Method: "GET", Path: "/acls/:pk/:related/:fk", Handler: controller.FindByIDRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("UpsertRelated"), &usecases.Route{Method: "PUT", Path: "/acls/:pk/:related", Handler: controller.UpsertRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("UpdateByIDRelated"), &usecases.Route{Method: "PUT", Path: "/acls/:pk/:related/:fk", Handler: controller.UpdateByIDRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("DeleteAllRelated"), &usecases.Route{Method: "DELETE", Path: "/acls/:pk/:related", Handler: controller.DeleteAllRelated, Visible: true, CheckPermissions: false})
routeDir.Add(key.For("DeleteByIDRelated"), &usecases.Route{Method: "DELETE", Path: "/acls/:pk/:related/:fk", Handler: controller.DeleteByIDRelated, Visible: true, CheckPermissions: false})
}
示例5: UpdatePasswordRelated
// @Title UpdatePasswordRelated
// @Description Update the related user password
// @Accept json
// @Param pk path int true "Account id"
// @Param fk path int true "User id"
// @Param PasswordForm body PasswordForm true "The old and the new password"
// @Success 200 {object} domain.User "Request was successful"
// @Router /accounts/{pk}/users/{fk}/updatePassword [post]
func (c *AccountCtrl) UpdatePasswordRelated(w http.ResponseWriter, r *http.Request, params map[string]string) {
var (
pk int
err error
)
if params["pk"] == "me" {
sessionCtx := context.Get(r, "currentSession")
if sessionCtx == nil {
c.render.JSONError(w, http.StatusUnauthorized, apierrors.SessionNotFound, nil)
return
}
pk = sessionCtx.(domain.Session).AccountID
} else {
pk, err = strconv.Atoi(params["pk"])
if err != nil {
c.render.JSONError(w, http.StatusBadRequest, apierrors.InvalidPathParams, err)
return
}
}
params["id"] = params["fk"]
key := usecases.NewDirectoryKey("users")
handler := c.routeDir.Get(key.For("UpdatePassword")).EffectiveHandler
if handler == nil {
c.render.JSON(w, http.StatusNotFound, nil)
return
}
context.Set(r, "lastResource", &interfaces.Resource{Name: "users", IDKey: "accountID", ID: pk})
handler(w, r, params)
}
示例6: AddRoutes
func (s *Swagger) AddRoutes(routeDir *usecases.RouteDirectory) {
dirKey := usecases.NewDirectoryKey("swagger")
routeDir.Add(dirKey.For("UI"), &usecases.Route{Method: "GET", Path: "/explorer", Handler: s.UIHandler, Visible: true, CheckPermissions: false})
routeDir.Add(dirKey.For("Resources"), &usecases.Route{Method: "GET", Path: "/explorer/*path", Handler: s.ResourcesHandler, Visible: true, CheckPermissions: false})
}