本文整理汇总了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, ¶ms)
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)
}
示例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, ¶ms)
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)
}
示例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
}
示例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, ¶ms)
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)
}
示例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, ¶ms)
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)
}
示例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, ¶ms)
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)
}
示例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, ¶ms)
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)
}
示例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)
}
示例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)
}