本文整理汇总了Golang中github.com/pomack/webmachine/go/webmachine.Request类的典型用法代码示例。如果您正苦于以下问题:Golang Request类的具体用法?Golang Request怎么用?Golang Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: ContentTypesAccepted
func (p *LoginAccountRequestHandler) ContentTypesAccepted(req wm.Request, cxt wm.Context) ([]wm.MediaTypeInputHandler, wm.Request, wm.Context, int, error) {
arr := []wm.MediaTypeInputHandler{
apiutil.NewJSONMediaTypeInputHandler("", "", p, req.Body()),
apiutil.NewUrlEncodedMediaTypeInputHandler("", "", p),
}
return arr, req, cxt, 0, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:7,代码来源:login.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 *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
示例5: 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
示例6: IsAuthorized
func (p *UpdateContactRequestHandler) IsAuthorized(req wm.Request, cxt wm.Context) (bool, string, wm.Request, wm.Context, int, error) {
ucc := cxt.(UpdateContactContext)
hasSignature, userId, _, err := apiutil.CheckSignature(p.authDS, req.UnderlyingRequest())
if !hasSignature || err != nil {
return hasSignature, "dsocial", req, cxt, http.StatusUnauthorized, err
}
if userId != "" {
user, _ := p.ds.RetrieveUserAccountById(userId)
ucc.SetAuthUser(user)
}
return userId != "", "", req, cxt, 0, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:12,代码来源:update.go
示例7: IsAuthorized
func (p *LogoutAccountRequestHandler) IsAuthorized(req wm.Request, cxt wm.Context) (bool, string, wm.Request, wm.Context, int, error) {
lac := cxt.(LogoutAccountContext)
hasSignature, userId, _, err := apiutil.CheckSignature(p.authDS, req.UnderlyingRequest())
if !hasSignature || err != nil {
return hasSignature, "dsocial", req, cxt, http.StatusUnauthorized, err
}
accessKey, _ := apiutil.RetrieveAccessKeyFromRequest(p.authDS, req.UnderlyingRequest())
lac.SetAccessKey(accessKey)
if userId != "" {
user, _ := p.ds.RetrieveUserAccountById(userId)
lac.SetUser(user)
}
return true, "", req, cxt, 0, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:14,代码来源:logout.go
示例8: IsAuthorized
func (p *ViewAccountRequestHandler) IsAuthorized(req wm.Request, cxt wm.Context) (bool, string, wm.Request, wm.Context, int, error) {
vac := cxt.(ViewAccountContext)
hasSignature, userId, consumerId, err := apiutil.CheckSignature(p.authDS, req.UnderlyingRequest())
if !hasSignature || err != nil {
return hasSignature, "dsocial", req, cxt, http.StatusUnauthorized, err
}
if userId != "" {
user, _ := p.ds.RetrieveUserAccountById(userId)
vac.SetRequestingUser(user)
}
if consumerId != "" {
consumer, _ := p.ds.RetrieveConsumerAccountById(consumerId)
vac.SetRequestingConsumer(consumer)
}
return true, "", req, cxt, 0, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:16,代码来源:view.go
示例9: 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
示例10: 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
示例11: 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
示例12: IsAuthorized
func (p *GeneratePrivateKeyRequestHandler) IsAuthorized(req wm.Request, cxt wm.Context) (bool, string, wm.Request, wm.Context, int, error) {
gpkc := cxt.(GeneratePrivateKeyContext)
hasSignature, userId, consumerId, err := apiutil.CheckSignature(p.authDS, req.UnderlyingRequest())
if !hasSignature || err != nil {
return hasSignature, "dsocial", req, cxt, http.StatusUnauthorized, err
}
if userId != "" {
user, _ := p.ds.RetrieveUserAccountById(userId)
gpkc.SetUser(user)
}
if consumerId != "" {
consumer, _ := p.ds.RetrieveConsumerAccountById(consumerId)
gpkc.SetConsumer(consumer)
}
if (userId != "" && gpkc.User() == nil) || (consumerId != "" && gpkc.Consumer() == nil) {
gpkc.SetUser(nil)
gpkc.SetConsumer(nil)
}
return true, "", req, cxt, 0, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:20,代码来源:generate_private_key.go
示例13: 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
示例14: 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
示例15: 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
示例16: Forbidden
func (p *CreateAccountRequestHandler) Forbidden(req wm.Request, cxt wm.Context) (bool, wm.Request, wm.Context, int, os.Error) {
cac := cxt.(CreateAccountContext)
hasSignature, userId, consumerId, err := apiutil.CheckSignature(p.authDS, req.UnderlyingRequest())
if err != nil {
return true, req, cxt, 403, err
}
if hasSignature {
if userId != "" {
user, _ := p.ds.RetrieveUserAccountById(userId)
cac.SetRequestingUser(user)
}
if consumerId != "" {
consumer, _ := p.ds.RetrieveConsumerAccountById(consumerId)
cac.SetRequestingConsumer(consumer)
}
if (userId != "" && (cac.RequestingUser() == nil || !cac.RequestingUser().Accessible())) && (consumerId != "" && (cac.RequestingConsumer() == nil || !cac.RequestingConsumer().Accessible())) {
// Cannot find user or consumer with specified id
return true, req, cxt, 0, nil
}
}
return false, req, cxt, 0, nil
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:22,代码来源:create.go
示例17: MediaTypeHandleInputFrom
func (p *UrlEncodedMediaTypeInputHandler) MediaTypeHandleInputFrom(req wm.Request, cxt wm.Context) (int, http.Header, io.WriterTo) {
m := req.Form()
if m == nil || len(m) == 0 {
if err := req.ParseForm(); err != nil {
return OutputErrorMessage(err.Error(), nil, http.StatusBadRequest, nil)
}
m = req.Form()
}
return p.handler.HandleUrlEncodedInputHandler(req, cxt, m)
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:10,代码来源:urlencodedmediatypeinputhandler.go
示例18: ContentTypesAccepted
func (p *UpdateContactRequestHandler) ContentTypesAccepted(req wm.Request, cxt wm.Context) ([]wm.MediaTypeInputHandler, wm.Request, wm.Context, int, error) {
arr := []wm.MediaTypeInputHandler{apiutil.NewJSONMediaTypeInputHandler("", "", p, req.Body())}
return arr, req, cxt, 0, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:4,代码来源:update.go
注:本文中的github.com/pomack/webmachine/go/webmachine.Request类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论