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

Golang rpc.Args类代码示例

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

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



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

示例1: SignInLogin

// RPC/SignInLogin logs in a user, specified by their login (aka username)
// Args:
//   "L" string
//   "P" string = HMAC-hashed password
// Err:
//   ErrApp:  If the sign-in information is incorrect
//   non-nil: If a technical problem occured
//
func (a *API) SignInLogin(args *rpc.Args, r *rpc.Ret) (err os.Error) {

	// Validate and sanitize arguments
	login, _ := args.QueryString("L")
	if login, err = SanitizeLogin(login); err != nil {
		return ErrApp
	}
	hpass, _ := args.QueryString("P")

	// Fetch user for this login
	u, _, err := a.db.FindUserByLogin(login)
	if err != nil {
		return ErrDb
	}
	if u == nil {
		return ErrApp
	}

	// Verify credentials
	if !VerifyPassword(hpass, u.Password) {
		return ErrSec
	}

	r.AddSetCookie(a.newUserAuthCookie(u))
	r.AddSetCookie(a.newUserNameCookie(u))
	r.AddSetCookie(a.newUserNymCookie(u))

	r.SetInt("XPad", 0)
	return nil
}
开发者ID:petar,项目名称:ShelfLife,代码行数:38,代码来源:login.go


示例2: FindMsgAttachedTo

func (a *API) FindMsgAttachedTo(args *rpc.Args, r *rpc.Ret) (err os.Error) {
	attachTo, err := args.QueryString("AttachTo")
	if err != nil || attachTo == "" {
		return ErrArg
	}
	joins, err := a.db.FindMsgAttachedTo(attachTo)
	if err != nil {
		return err
	}
	q := make([]msgJoinJSON, len(joins))
	for i, join := range joins {
		author, err := a.whoIsID(join.Author)
		if err != nil {
			log.Printf("Unresolved author ID: %s", join.Author)
			q[i].AuthorNym = "anonymous"
		} else {
			q[i].AuthorNym = author.Login
		}
		q[i].ID = WebStringOfObjectID(join.ID)
		q[i].Body = join.Doc.Body
		q[i].AuthorID = WebStringOfObjectID(join.Author)
		q[i].AttachTo = WebStringOfObjectID(join.AttachTo)
		q[i].ReplyTo = WebStringOfObjectID(join.ReplyTo)
		modtm := time.NanosecondsToLocalTime(int64(join.Modified)).Format(msgFormat)
		q[i].Modified = modtm
	}
	r.SetInterface("Results", q)
	return nil
}
开发者ID:petar,项目名称:ShelfLife,代码行数:29,代码来源:msg.go


示例3: UnsetFollow

func (a *API) UnsetFollow(args *rpc.Args, r *rpc.Ret) (err os.Error) {
	_, uid, err := a.whoAmI(args)
	if err != nil {
		return err
	}
	what, _ := args.QueryString("What")
	r.SetInt("XPad", 0)
	return a.db.UnsetFollow(uid, what)
}
开发者ID:petar,项目名称:ShelfLife,代码行数:9,代码来源:follow.go


示例4: Unlike

func (a *API) Unlike(args *rpc.Args, r *rpc.Ret) (err os.Error) {
	fid, _ := args.QueryString("FID")
	_, uid, err := a.whoAmI(args)
	if err != nil {
		return err
	}
	r.SetInt("XPad", 0)
	return a.db.Unlike(uid, fid)
}
开发者ID:petar,项目名称:ShelfLife,代码行数:9,代码来源:like.go


示例5: RemoveMsg

// RemoveMsg deletes a message
func (a *API) RemoveMsg(args *rpc.Args, r *rpc.Ret) (err os.Error) {
	_, editorID, err := a.whoAmI(args)
	if err != nil {
		return err
	}
	msg, err := args.QueryString("Msg")
	if err != nil {
		return err
	}
	r.SetInt("XPad", 0)
	return a.db.RemoveMsg(editorID, ObjectIDOfWebString(msg))
}
开发者ID:petar,项目名称:ShelfLife,代码行数:13,代码来源:msg.go


示例6: IsLoginAvailable

// IsLoginAvailable checks if this login (i.e. username) is already taken
func (a *API) IsLoginAvailable(args *rpc.Args, r *rpc.Ret) os.Error {
	login, err := args.QueryString("L")
	if err != nil {
		return err
	}
	if login, err = SanitizeLogin(login); err != nil {
		return rpc.ErrArg
	}
	u, _, err := a.db.FindUserByLogin(login)
	if err != nil {
		return ErrDb
	}
	r.SetBool("Available", u == nil)
	return nil
}
开发者ID:petar,项目名称:ShelfLife,代码行数:16,代码来源:login.go


示例7: EditMsg

// EditMsg changes the body of an existing message
func (a *API) EditMsg(args *rpc.Args, r *rpc.Ret) (err os.Error) {
	_, editorID, err := a.whoAmI(args)
	if err != nil {
		return err
	}
	msg, err := args.QueryString("Msg")
	if err != nil {
		return err
	}
	body, err := args.QueryString("Body")
	if err != nil || body == "" {
		return ErrArg
	}
	r.SetInt("XPad", 0)
	return a.db.EditMsg(editorID, ObjectIDOfWebString(msg), body)
}
开发者ID:petar,项目名称:ShelfLife,代码行数:17,代码来源:msg.go


示例8: LikeInfo

func (a *API) LikeInfo(args *rpc.Args, r *rpc.Ret) (err os.Error) {
	fid, _ := args.QueryString("FID")
	_, uid, err := a.whoAmI(args)
	if err != nil {
		return err
	}
	likes, err := a.db.Likes(uid, fid)
	if err != nil {
		likes = false
	}
	n, err := a.db.LikeCount(fid)
	if err != nil {
		return err
	}
	r.SetBool("Likes", likes)
	r.SetInt("Count", n)
	return nil
}
开发者ID:petar,项目名称:ShelfLife,代码行数:18,代码来源:like.go


示例9: AddMsg

// AddMsg adds a new message to the database. The author is the currently
// logged in user. The message is attached to the object given by the string
// argument "AttachTo". Optionally, the message is in response to another message
// with message ID "ReplyTo". AddMsg returns the message ID of the newly added
// message, in the return field "ID".
func (a *API) AddMsg(args *rpc.Args, r *rpc.Ret) (err os.Error) {
	authorDoc, authorID, err := a.whoAmI(args)
	if err != nil {
		return err
	}
	attachTo, err := args.QueryString("AttachTo")
	if err != nil || attachTo == "" {
		return ErrArg
	}
	replyTo, _ := args.QueryString("ReplyTo")
	body, err := args.QueryString("Body")
	if err != nil || body == "" {
		return ErrArg
	}
	msgID, err := a.db.AddMsg(authorID, attachTo, ObjectIDOfWebString(replyTo), body)
	if err != nil {
		return err
	}
	j := msgJoinJSON{
		ID:        WebStringOfObjectID(msgID),
		Body:      body,
		AuthorID:  WebStringOfObjectID(authorID),
		AuthorNym: authorDoc.Login,
		AttachTo:  attachTo,
		ReplyTo:   replyTo,
		Modified:  time.NanosecondsToLocalTime(int64(bson.Now())).Format(msgFormat),
	}
	r.SetInterface("Msg", j)
	return nil
}
开发者ID:petar,项目名称:ShelfLife,代码行数:35,代码来源:msg.go


示例10: FollowInfo

// FollowInfo returns true if the logged user follows the given object
func (a *API) FollowInfo(args *rpc.Args, r *rpc.Ret) (err os.Error) {

	_, uid, err := a.whoAmI(args)
	if err != nil {
		return err
	}
	what, _ := args.QueryString("What")

	follows, err := a.db.IsFollow(uid, what)
	if err != nil {
		follows = false
	}

	n, err := a.db.FollowerCount(what)
	if err != nil {
		return err
	}

	r.SetBool("Follows", follows)
	r.SetInt("Count", n)

	return nil
}
开发者ID:petar,项目名称:ShelfLife,代码行数:24,代码来源:follow.go


示例11: SignUp

// SignUp registers a new user
func (a *API) SignUp(args *rpc.Args, r *rpc.Ret) (err os.Error) {

	// Validate and sanitize arguments
	name, _ := args.QueryString("N")
	if name, err = SanitizeName(name); err != nil {
		return ErrApp
	}
	email, _ := args.QueryString("E")
	if email, err = SanitizeEmail(email); err != nil {
		return ErrApp
	}
	login, _ := args.QueryString("L")
	if login, err = SanitizeLogin(login); err != nil {
		return ErrApp
	}
	hpass, _ := args.QueryString("P")

	// Check that a user like this doesn't already exist
	u, _, err := a.db.FindUserByLogin(login)
	if err != nil {
		return ErrDb
	}
	if u != nil {
		return ErrApp
	}
	u, err = a.db.FindUserByEmail(email)
	if err != nil {
		return ErrDb
	}
	if u != nil {
		return ErrApp
	}

	// Add the user
	u = &db.UserDoc{
		Name:     name,
		Login:    login,
		Email:    email,
		Password: hpass,
	}
	if _, err = a.db.AddUser(u); err != nil {
		return ErrDb
	}

	r.SetInt("XPad", 0)
	return nil
}
开发者ID:petar,项目名称:ShelfLife,代码行数:48,代码来源:login.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang rpc.Ret类代码示例发布时间:2022-05-28
下一篇:
Golang dccp.Amb类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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