當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ReqCtx.Params方法代碼示例

本文整理匯總了Golang中github.com/neptulon/neptulon.ReqCtx.Params方法的典型用法代碼示例。如果您正苦於以下問題:Golang ReqCtx.Params方法的具體用法?Golang ReqCtx.Params怎麽用?Golang ReqCtx.Params使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/neptulon/neptulon.ReqCtx的用法示例。


在下文中一共展示了ReqCtx.Params方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Echo

// Echo sends incoming messages back as is.
func Echo(ctx *neptulon.ReqCtx) error {
	// unmarshall incoming message into response directly
	if err := ctx.Params(&ctx.Res); err != nil {
		return err
	}
	return ctx.Next()
}
開發者ID:soygul,項目名稱:neptulon,代碼行數:8,代碼來源:echo.go

示例2: googleAuth

// googleAuth authenticates a user with Google+ using provided OAuth 2.0 access token.
// If authenticated successfully, user profile is retrieved from Google+ and user is given a JWT token in return.
func googleAuth(ctx *neptulon.ReqCtx, db DB, pass string) error {
	var r tokenContainer
	if err := ctx.Params(&r); err != nil || r.Token == "" {
		ctx.Err = &neptulon.ResError{Code: 666, Message: "Malformed or null Google oauth access token was provided."}
		return fmt.Errorf("auth: google: malformed or null Google oauth token '%v' was provided: %v", r.Token, err)
	}

	p, err := getTokenInfo(r.Token)
	if err != nil {
		ctx.Err = &neptulon.ResError{Code: 666, Message: "Failed to authenticated with the given Google oauth access token."}
		return fmt.Errorf("auth: google: error during Google API call using provided token: %v with error: %v", r.Token, err)
	}

	// retrieve user information
	user, ok := db.GetByMail(p.Email)
	if !ok {
		// this is a first-time registration so create user profile via Google+ profile info
		user = &User{Email: p.Email, Name: p.Name, Picture: p.Picture, Registered: time.Now()}

		// save the user information for user ID to be generated by the database
		if err := db.SaveUser(user); err != nil {
			return fmt.Errorf("auth: google: failed to persist user information: %v", err)
		}

		// create the JWT token
		token := jwt.New(jwt.SigningMethodHS256)
		token.Claims["userid"] = user.ID
		token.Claims["created"] = user.Registered.Unix()
		user.JWTToken, err = token.SignedString([]byte(pass))
		if err != nil {
			return fmt.Errorf("auth: google: jwt signing error: %v", err)
		}

		// now save the full user info
		if err := db.SaveUser(user); err != nil {
			return fmt.Errorf("auth: google: failed to persist user information: %v", err)
		}

		// store user ID in session so user can make authenticated call after this
		ctx.Conn.Session.Set("userid", user.ID)
	}

	ctx.Res = gAuthRes{ID: user.ID, Token: user.JWTToken, Name: user.Name, Email: user.Email, Picture: user.Picture}
	ctx.Session.Set(middleware.CustResLogDataKey, gAuthRes{ID: user.ID, Token: user.JWTToken, Name: user.Name, Email: user.Email})
	log.Printf("auth: google: logged in: %v, %v", p.Name, p.Email)
	return nil
}
開發者ID:nbusy,項目名稱:nbusy,代碼行數:49,代碼來源:auth_google.go

示例3: Logger

// Logger is an incoming/outgoing message logger.
func Logger(ctx *neptulon.ReqCtx) error {
	var v interface{}
	ctx.Params(&v)

	err := ctx.Next()

	var res interface{}
	if res = ctx.Session.Get(CustResLogDataKey); res == nil {
		res = ctx.Res
		if res == nil {
			res = ctx.Err
		}
	}

	log.Printf("mw: logger: %v: %v, in: \"%v\", out: \"%#v\"", ctx.ID, ctx.Method, v, res)

	return err
}
開發者ID:nbusy,項目名稱:nbusy,代碼行數:19,代碼來源:logger.go


注:本文中的github.com/neptulon/neptulon.ReqCtx.Params方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。