当前位置: 首页>>代码示例>>Golang>>正文


Golang Request.URLParts方法代码示例

本文整理汇总了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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:35,代码来源:delete.go

示例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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:26,代码来源:view.go

示例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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:28,代码来源:update.go

示例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
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:8,代码来源:create.go

示例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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:18,代码来源:view.go

示例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 ""
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:19,代码来源:requestparser.go

示例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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:19,代码来源:update.go

示例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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:21,代码来源:logout.go

示例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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:21,代码来源:generate_private_key.go

示例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
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:21,代码来源:set_password.go


注:本文中的github.com/pomack/webmachine/go/webmachine.Request.URLParts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。