當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。