• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang db.ReadJSONFromMIME函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/couchbaselabs/sync_gateway/db.ReadJSONFromMIME函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadJSONFromMIME函数的具体用法?Golang ReadJSONFromMIME怎么用?Golang ReadJSONFromMIME使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ReadJSONFromMIME函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: handleBrowserIDPOST

// POST /_browserid creates a browserID-based login session and sets its cookie.
// It's API-compatible with the CouchDB plugin: <https://github.com/iriscouch/browserid_couchdb/>
func (h *handler) handleBrowserIDPOST() error {
	var params struct {
		Assertion string `json:"assertion"`
	}
	err := db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, &params)
	if err != nil {
		return err
	}
	if h.context.serverURL == "" {
		log.Printf("Warning: Can't accept BrowserID logins: Server URL not configured")
		return &base.HTTPError{http.StatusInternalServerError, "Server url not configured"}
	}

	// OK, now verify it:
	log.Printf("BrowserID: Verifying assertion %q for %q", params.Assertion, h.context.serverURL)
	verifiedInfo, err := VerifyBrowserID(params.Assertion, h.context.serverURL)
	if err != nil {
		log.Printf("BrowserID: Failed verify: %v", err)
		return err
	}
	log.Printf("BrowserID: Logged in %q!", verifiedInfo.Email)

	// Email is verified. Look up the user and make a login session for her:
	auth := h.context.auth
	user, err := auth.GetUserByEmail(verifiedInfo.Email)
	if err != nil {
		return err
	}
	return h.makeSession(user)
}
开发者ID:jchris,项目名称:sync_gateway,代码行数:32,代码来源:browserid.go


示例2: handlePersonaPOST

// POST /_persona creates a browserID-based login session and sets its cookie.
// It's API-compatible with the CouchDB plugin: <https://github.com/iriscouch/browserid_couchdb/>
func (h *handler) handlePersonaPOST() error {
	var params struct {
		Assertion string `json:"assertion"`
	}
	err := db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, &params)
	if err != nil {
		return err
	}

	origin := h.server.config.Persona.Origin
	if origin == "" {
		base.Warn("Can't accept Persona logins: Server URL not configured")
		return &base.HTTPError{http.StatusInternalServerError, "Server url not configured"}
	}

	// OK, now verify it:
	base.Log("Persona: Verifying assertion %q for %q", params.Assertion, origin)
	verifiedInfo, err := VerifyPersona(params.Assertion, origin)
	if err != nil {
		base.Log("Persona: Failed verify: %v", err)
		return err
	}
	base.Log("Persona: Logged in %q!", verifiedInfo.Email)

	createUserIfNeeded := h.server.config.Persona.Register
	return h.makeSessionFromEmail(verifiedInfo.Email, createUserIfNeeded)

}
开发者ID:nvdbleek,项目名称:sync_gateway,代码行数:30,代码来源:persona.go


示例3: handleRevsDiff

func (h *handler) handleRevsDiff() error {
	var input db.RevsDiffInput
	err := db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, &input)
	if err != nil {
		return err
	}
	output, err := h.db.RevsDiff(input)
	if err == nil {
		h.writeJSON(output)
	}
	return err
}
开发者ID:robertkrimen,项目名称:sync_gateway,代码行数:12,代码来源:rest.go


示例4: handleFacebookPOST

// POST /_facebook creates a facebook-based login session and sets its cookie.
func (h *handler) handleFacebookPOST() error {

	var params struct {
		AccessToken string `json:"access_token"`
	}
	err := db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, &params)
	if err != nil {
		return err
	}

	facebookResponse, err := verifyFacebook(kFacebookOpenGraphURL, params.AccessToken)
	if err != nil {
		return err
	}

	createUserIfNeeded := h.server.config.Facebook.Register
	return h.makeSessionFromEmail(facebookResponse.Email, createUserIfNeeded)

}
开发者ID:nod,项目名称:sync_gateway,代码行数:20,代码来源:facebook.go


示例5: handleSessionPOST

// POST /_session creates a login session and sets its cookie
func (h *handler) handleSessionPOST() error {
	var params struct {
		Name     string `json:"name"`
		Password string `json:"password"`
	}
	err := db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, &params)
	if err != nil {
		return err
	}
	var user auth.User
	user, err = h.db.Authenticator().GetUser(params.Name)
	if err != nil {
		return err
	}
	if !user.Authenticate(params.Password) {
		user = nil
	}
	return h.makeSession(user)
}
开发者ID:CloudMetal,项目名称:sync_gateway,代码行数:20,代码来源:session_api.go


示例6: handlePersonaPOST

// POST /_persona creates a browserID-based login session and sets its cookie.
// It's API-compatible with the CouchDB plugin: <https://github.com/iriscouch/browserid_couchdb/>
func (h *handler) handlePersonaPOST() error {
	var params struct {
		Assertion string `json:"assertion"`
	}
	err := db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, &params)
	if err != nil {
		return err
	}

	origin := h.server.config.Persona.Origin
	if origin == "" {
		base.Warn("Can't accept Persona logins: Server URL not configured")
		return &base.HTTPError{http.StatusInternalServerError, "Server url not configured"}
	}

	// OK, now verify it:
	base.Log("Persona: Verifying assertion %q for %q", params.Assertion, origin)
	verifiedInfo, err := VerifyPersona(params.Assertion, origin)
	if err != nil {
		base.Log("Persona: Failed verify: %v", err)
		return err
	}
	base.Log("Persona: Logged in %q!", verifiedInfo.Email)

	// Email is verified. Look up the user and make a login session for her:
	user, err := h.db.Authenticator().GetUserByEmail(verifiedInfo.Email)
	if err != nil {
		return err
	}
	if user == nil {
		// The email address is authentic but we have no user account for it.
		if !h.server.config.Persona.Register {
			return &base.HTTPError{http.StatusUnauthorized, "No such user"}
		}
		// Create a User with the given email address as username and a random password.
		user, err = h.registerPersonaUser(verifiedInfo)
		if err != nil {
			return err
		}
	}
	return h.makeSession(user)
}
开发者ID:CloudMetal,项目名称:sync_gateway,代码行数:44,代码来源:persona.go


示例7: handleBrowserIDPOST

// POST /_browserid creates a browserID-based login session and sets its cookie.
// It's API-compatible with the CouchDB plugin: <https://github.com/iriscouch/browserid_couchdb/>
func (h *handler) handleBrowserIDPOST() error {
	var params struct {
		Assertion string `json:"assertion"`
	}
	err := db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, &params)
	if err != nil {
		return err
	}
	if h.context.serverURL == "" {
		log.Printf("Warning: Can't accept BrowserID logins: Server URL not configured")
		return &base.HTTPError{http.StatusInternalServerError, "Server url not configured"}
	}

	// OK, now verify it:
	log.Printf("BrowserID: Verifying assertion %q for %q", params.Assertion, h.context.serverURL)
	verifiedInfo, err := VerifyBrowserID(params.Assertion, h.context.serverURL)
	if err != nil {
		log.Printf("BrowserID: Failed verify: %v", err)
		return err
	}
	log.Printf("BrowserID: Logged in %q!", verifiedInfo.Email)

	// Email is verified. Look up the user and make a login session for her:
	user, err := h.context.auth.GetUserByEmail(verifiedInfo.Email)
	if err != nil {
		return err
	}
	if user == nil {
		// The email address is authentic but we have no user account for it.
		// Create a User for this session, with the given email address but no
		// channel access and a random password.
		user, err = h.registerBrowserIDUser(verifiedInfo)
		if err != nil {
			return err
		}
	}
	return h.makeSession(user)
}
开发者ID:PatrickHeneise,项目名称:sync_gateway,代码行数:40,代码来源:browserid.go


示例8: readJSON

// Parses a JSON request body, returning it as a Body map.
func (h *handler) readJSON() (db.Body, error) {
	var body db.Body
	return body, db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, &body)
}
开发者ID:PatrickHeneise,项目名称:sync_gateway,代码行数:5,代码来源:handler.go


示例9: readJSONInto

// Parses a JSON request body into a custom structure.
func (h *handler) readJSONInto(into interface{}) error {
	return db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, into)
}
开发者ID:CloudMetal,项目名称:sync_gateway,代码行数:4,代码来源:handler.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang db.ChangesOptions类代码示例发布时间:2022-05-23
下一篇:
Golang channels.TimedSet类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap