本文整理匯總了Golang中github.com/petar/GoHTTP/server/rpc.Ret.SetInterface方法的典型用法代碼示例。如果您正苦於以下問題:Golang Ret.SetInterface方法的具體用法?Golang Ret.SetInterface怎麽用?Golang Ret.SetInterface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/petar/GoHTTP/server/rpc.Ret
的用法示例。
在下文中一共展示了Ret.SetInterface方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}