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


Golang db.ReadJSONFromMIME函数代码示例

本文整理汇总了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;未经允许,请勿转载。