本文整理汇总了Golang中github.com/pomack/webmachine/go/webmachine.Request.URLParts方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.URLParts方法的具体用法?Golang Request.URLParts怎么用?Golang Request.URLParts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pomack/webmachine/go/webmachine.Request
的用法示例。
在下文中一共展示了Request.URLParts方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ResourceExists
func (p *DeleteContactRequestHandler) ResourceExists(req wm.Request, cxt wm.Context) (bool, wm.Request, wm.Context, int, error) {
dcc := cxt.(DeleteContactContext)
path := req.URLParts()
pathLen := len(path)
if path[pathLen-1] == "" {
// ignore trailing slash
pathLen = pathLen - 1
}
contactId := ""
if pathLen == 9 {
contactId = path[8]
} else if pathLen == 6 {
contactId = path[5]
}
dcc.SetContactId(contactId)
if contactId == "" || dcc.User() == nil || dcc.User().Id == "" {
return false, req, cxt, 0, nil
}
contact, _, err := p.contactsDS.RetrieveDsocialContact(dcc.User().Id, contactId)
dcc.SetContact(contact)
if contact != nil {
dcc.SetETag(contact.Etag)
if contact.ModifiedAt > 0 {
dcc.SetLastModified(time.Unix(contact.ModifiedAt, 0).UTC())
}
} else {
dcc.SetETag("")
dcc.SetLastModified(time.Time{})
}
httpStatus := 0
if err != nil {
httpStatus = http.StatusInternalServerError
}
return contact != nil, req, cxt, httpStatus, err
}
示例2: StartRequest
func (p *ViewAccountRequestHandler) StartRequest(req wm.Request, cxt wm.Context) (wm.Request, wm.Context) {
vac := p.GenerateContext(req, cxt)
path := req.URLParts()
pathLen := len(path)
if pathLen >= 8 {
vac.SetType(path[5])
var id string
if path[pathLen-1] == "" {
id = strings.Join(path[7:pathLen-1], "/")
} else {
id = strings.Join(path[7:], "/")
}
switch vac.Type() {
case "user":
user, _ := p.ds.RetrieveUserAccountById(id)
vac.SetUser(user)
case "consumer":
consumer, _ := p.ds.RetrieveConsumerAccountById(id)
vac.SetConsumer(consumer)
case "external_user":
externalUser, _ := p.ds.RetrieveExternalUserAccountById(id)
vac.SetExternalUser(externalUser)
}
}
return req, vac
}
示例3: StartRequest
func (p *UpdateContactRequestHandler) StartRequest(req wm.Request, cxt wm.Context) (wm.Request, wm.Context) {
ucc := p.GenerateContext(req, cxt)
path := req.URLParts()
pathLen := len(path)
if path[pathLen-1] == "" {
// ignore trailing slash
pathLen = pathLen - 1
}
var userId string
var contactId string
switch pathLen {
case 9:
userId = path[5]
contactId = path[8]
case 6:
userId = path[2]
contactId = path[5]
}
if userId != "" {
user, _ := p.ds.RetrieveUserAccountById(userId)
ucc.SetUser(user)
if contactId != "" {
contact, _, _ := p.contactsDS.RetrieveDsocialContact(userId, contactId)
ucc.SetOriginalContact(contact)
}
}
return req, ucc
}
示例4: StartRequest
func (p *CreateAccountRequestHandler) StartRequest(req wm.Request, cxt wm.Context) (wm.Request, wm.Context) {
cac := p.GenerateContext(req, cxt)
path := req.URLParts()
if len(path) >= 6 {
cac.SetType(path[5])
}
return req, cac
}
示例5: HandlerFor
func (p *ViewAccountRequestHandler) HandlerFor(req wm.Request, writer wm.ResponseWriter) wm.RequestHandler {
// /api/v1/json/account/(user|consumer|external_user)/view/(id)
path := req.URLParts()
pathLen := len(path)
if path[pathLen-1] == "" {
// ignore trailing slash
pathLen = pathLen - 1
}
if pathLen >= 8 {
if path[0] == "" && path[1] == "api" && path[2] == "v1" && path[3] == "json" && path[4] == "account" && path[6] == "view" {
switch path[5] {
case "user", "consumer", "external_user":
return p
}
}
}
return nil
}
示例6: UserIdFromRequestUrl
func UserIdFromRequestUrl(req wm.Request) string {
path := req.URLParts()
pathLen := len(path)
if path[pathLen-1] == "" {
// ignore trailing slash
pathLen = pathLen - 1
}
if pathLen >= 6 {
if path[0] == "" && path[1] == "api" && path[2] == "v1" && path[3] == "json" && path[4] == "u" {
return path[5]
}
}
if pathLen >= 3 {
if path[0] == "" && path[1] == "u" {
return path[2]
}
}
return ""
}
示例7: HandlerFor
func (p *UpdateContactRequestHandler) HandlerFor(req wm.Request, writer wm.ResponseWriter) wm.RequestHandler {
// /api/v1/json/account/(user|consumer|external_user)/update/(id)
path := req.URLParts()
pathLen := len(path)
if path[pathLen-1] == "" {
// ignore trailing slash
pathLen = pathLen - 1
}
if pathLen == 9 {
if path[0] == "" && path[1] == "api" && path[2] == "v1" && path[3] == "json" && path[4] == "u" && path[5] != "" && path[6] == "contacts" && path[7] == "update" && path[8] != "" {
return p
}
} else if pathLen == 6 {
if path[0] == "" && path[1] == "u" && path[2] != "" && path[3] == "contacts" && path[4] == "update" && path[5] != "" {
return p
}
}
return nil
}
示例8: HandlerFor
func (p *LogoutAccountRequestHandler) HandlerFor(req wm.Request, writer wm.ResponseWriter) wm.RequestHandler {
// /api/v1/json/auth/logout
// /auth/logout
path := req.URLParts()
pathLen := len(path)
if path[pathLen-1] == "" {
// ignore trailing slash
pathLen = pathLen - 1
}
if pathLen == 6 {
if path[0] == "" && path[1] == "api" && path[2] == "v1" && path[3] == "json" && path[4] == "auth" && path[5] == "logout" {
return p
}
}
if pathLen == 3 {
if path[0] == "" && path[1] == "auth" && path[2] == "logout" {
return p
}
}
return nil
}
示例9: HandlerFor
func (p *GeneratePrivateKeyRequestHandler) HandlerFor(req wm.Request, writer wm.ResponseWriter) wm.RequestHandler {
// /api/v1/json/auth/login
// /auth/login
path := req.URLParts()
pathLen := len(path)
if path[pathLen-1] == "" {
// ignore trailing slash
pathLen = pathLen - 1
}
if pathLen == 6 {
if path[0] == "" && path[1] == "api" && path[2] == "v1" && path[3] == "json" && path[4] == "auth" && path[5] == "generate_private_key" {
return p
}
}
if pathLen == 3 {
if path[0] == "" && path[1] == "auth" && path[2] == "generate_private_key" {
return p
}
}
return nil
}
示例10: HandlerFor
func (p *SetPasswordRequestHandler) HandlerFor(req wm.Request, writer wm.ResponseWriter) wm.RequestHandler {
// /api/v1/json/auth/set_password
// /auth/set_password
path := req.URLParts()
pathLen := len(path)
if path[pathLen-1] == "" {
// ignore trailing slash
pathLen = pathLen - 1
}
if pathLen == 6 {
if path[0] == "" && path[1] == "api" && path[2] == "v1" && path[3] == "json" && path[4] == "auth" && path[5] == "set_password" {
return p
}
}
if pathLen == 3 {
if path[0] == "" && path[1] == "auth" && path[2] == "set_password" {
return p
}
}
return nil
}