当前位置: 首页>>代码示例>>Golang>>正文


Golang PermaNode.FromMap方法代码示例

本文整理汇总了Golang中lightwavegrapher.PermaNode.FromMap方法的典型用法代码示例。如果您正苦于以下问题:Golang PermaNode.FromMap方法的具体用法?Golang PermaNode.FromMap怎么用?Golang PermaNode.FromMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lightwavegrapher.PermaNode的用法示例。


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

示例1: handleOpen

func handleOpen(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	userid, sessionid, err := getSession(c, r)
	if err != nil {
		sendError(w, r, "No session cookie")
		return
	}
	// Read the request body
	jreq, err := ioutil.ReadAll(r.Body)
	if err != nil {
		http.Error(w, "Error reading request body", http.StatusInternalServerError)
		return
	}
	r.Body.Close()
	// Parse request
	var req openCloseRequest
	err = json.Unmarshal(jreq, &req)
	if err != nil {
		sendError(w, r, "Malformed JSON")
		return
	}
	// Load the channel infos
	var ch channelStruct
	if err = datastore.Get(c, datastore.NewKey("channel", userid+"/"+sessionid, 0, nil), &ch); err != nil {
		sendError(w, r, "Unknown channel: "+userid+"/"+sessionid)
		return
	}
	// Check
	if len(ch.OpenPermas) >= 10 {
		sendError(w, r, "Too many open channels")
		return
	}
	is_open := false
	for _, p := range ch.OpenPermas {
		if p == req.Perma {
			is_open = true
			break
		}
	}
	var perma grapher.PermaNode
	if !is_open {
		// Update channel infos
		ch.OpenPermas = append(ch.OpenPermas, req.Perma)
		_, err = datastore.Put(c, datastore.NewKey("channel", userid+"/"+sessionid, 0, nil), &ch)
		if err != nil {
			sendError(w, r, "Internal server error")
			return
		}
		// Repeat all blobs from this document.
		s := newStore(c)
		g := grapher.NewGrapher(userid, schema, s, s, nil)
		s.SetGrapher(g)
		ch := newChannelAPI(c, s, userid, sessionid, true, g)
		perma, err = g.Repeat(req.Perma, req.From)
		if err != nil {
			sendError(w, r, "Failed opening")
			return
		}
		fmt.Fprintf(w, `{"ok":true, "blobs":[%v]}`, strings.Join(ch.messageBuffer, ","))
	} else {
		fmt.Fprint(w, `{"ok":true, "blobs":[]}`)
	}

	if req.MarkAsRead {
		if perma == nil {
			s := newStore(c)
			data, err := s.GetPermaNode(req.Perma)
			if err != nil {
				log.Printf("Err: Failed reading permanode")
				return
			}
			perma = grapher.NewPermaNode(nil)
			perma.FromMap(req.Perma, data)
		}
		markAsRead(c, userid, perma.BlobRef(), perma.SequenceNumber()-1)
	}
}
开发者ID:AaronO,项目名称:lightwave,代码行数:77,代码来源:server.go


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