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

Golang jas.Context类代码示例

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

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



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

示例1: Get

//var count  int = 0
func (r *Radio) Get(ctx *jas.Context) {
	ctx.Data = "radio response"
	r.count = r.count + 1
	if r.count > 2 {
		ctx.Data = "more response"
	}
}
开发者ID:jchjjj,项目名称:learnGo,代码行数:8,代码来源:example.go


示例2: Get

func (*Sporocila) Get(ctx *jas.Context) { // `GET /sporocila/:offset`
	offset := ctx.RequireInt("offset")
	err, res := sporocilo.NajdiSporocila(int(offset))
	if err == nil {
		ctx.Data = res
	}
}
开发者ID:ubuntu-si,项目名称:go-ubuntusi-log,代码行数:7,代码来源:rest.go


示例3: GetAll

// GetAll dumps the entire database of nodes, including cached ones.
func (*Api) GetAll(ctx *jas.Context) {
	nodes, err := Db.DumpNodes()
	if err != nil {
		ctx.Error = jas.NewInternalError(err)
		l.Err(err)
		return
	}
	ctx.Data = nodes
}
开发者ID:rynomad,项目名称:Nei.ghbor.Net-Keystone,代码行数:10,代码来源:api.go


示例4: Get

func (*Weixin) Get(ctx *jas.Context) {
	fmt.Println("Get weixin")
	echostr := ctx.RequireString("echostr")
	nonce := ctx.RequireString("nonce")
	timestamp := ctx.RequireString("timestamp")
	sig := ctx.RequireString("signature")

	params := []string{nonce, timestamp, WEIXIN_TOKEN}
	sort.Sort(sort.StringSlice(params))
	data := ""
	for _, v := range params {
		data += v
	}
	sha1Sig := string(sha1s(data))

	ctx.Data = echostr
	if sig == sha1Sig {
		cfg := &jas.Config{}
		cfg.HijackWrite = func(writer io.Writer, ctx *jas.Context) int {
			len, _ := writer.Write([]byte(reflect.ValueOf(ctx.Data).String()))
			return len
		}
		//		ctx.SetConfig(cfg)
	}
}
开发者ID:zhdtty,项目名称:mornsail,代码行数:25,代码来源:weixin_servlet.go


示例5: GetEcho

// GetEcho responds with the remote address of the user
func (*Api) GetEcho(ctx *jas.Context) {
	if Conf.Verify.Netmask != nil {
		if !(*net.IPNet)(Conf.Verify.Netmask).Contains(net.IP(ctx.RemoteAddr)) {
			ctx.Data = ctx.RemoteAddr
		} else {
			ctx.Error = jas.NewRequestError("remote address not in subnet")
		}
	} else {
		ctx.Error = jas.NewRequestError("netmask not set")
	}
}
开发者ID:rschulman,项目名称:nodeatlas,代码行数:12,代码来源:api.go


示例6: Post

func (*Machines) Post(ctx *jas.Context) {
	log.Println("Machines.Post")

	var machine models.Machine
	ctx.Unmarshal(&machine)

	u4, _ := uuid.NewV4()
	machine.UUID = u4.String()

	go machine.Save()
	ctx.Data = machine
}
开发者ID:Altonymous,项目名称:api.6fusion.com,代码行数:12,代码来源:machines.go


示例7: GetAll

// GetAll dumps the entire database of nodes, including cached
// ones. If the form value `since` is supplied with a valid RFC3339
// timestamp, only nodes updated or cached more recently than that
// will be dumped. If 'geojson' is present, then the "data" field
// contains the dump in GeoJSON compliant form.
func (*Api) GetAll(ctx *jas.Context) {
	// We must invoke ParseForm() so that we can access ctx.Form.
	ctx.ParseForm()

	// In order to access this at the end, we need to declare nodes
	// here, so the results from the dump don't go out of scope.
	var nodes []*Node
	var err error

	// If the form value "since" was supplied, we will be doing a dump
	// based on update/retrieve time.
	if tstring := ctx.FormValue("since"); len(tstring) > 0 {
		var t time.Time
		t, err = time.Parse(time.RFC3339, tstring)
		if err != nil {
			ctx.Data = err.Error()
			ctx.Error = jas.NewRequestError("invalidTime")
			return
		}

		// Now, perform the time-based dump. Errors will be handled
		// outside the if block.
		nodes, err = Db.DumpChanges(t)
	} else {
		// If there was no "since," provide a simple full-database
		// dump.
		nodes, err = Db.DumpNodes()
	}

	// Handle any database errors here.
	if err != nil {
		ctx.Error = jas.NewInternalError(err)
		l.Err(err)
		return
	}

	// If the form value 'geojson' is included, dump in GeoJSON
	// form. Otherwise, just dump with normal marhshalling.
	if _, ok := ctx.Form["geojson"]; ok {
		ctx.Data = FeatureCollectionNodes(nodes)
	} else {
		mappedNodes, err := Db.CacheFormatNodes(nodes)
		if err != nil {
			ctx.Error = jas.NewInternalError(err)
			l.Err(err)
			return
		}
		ctx.Data = mappedNodes
	}
}
开发者ID:nycmeshnet,项目名称:nodeatlas,代码行数:55,代码来源:api.go


示例8: GetTuling

func (*Hello) GetTuling(ctx *jas.Context) {
	var req TulingRequest
	req.Info = "新闻"
	resp := DoTulingQuery(req)
	resp.Print()
	ctx.Data = "success"
}
开发者ID:zhdtty,项目名称:mornsail,代码行数:7,代码来源:web.go


示例9: GetChildMaps

func (*Api) GetChildMaps(ctx *jas.Context) {
	var err error
	ctx.Data, err = Db.DumpChildMaps()
	if err != nil {
		ctx.Error = jas.NewInternalError(err)
		l.Errf("Error dumping child maps: %s", err)
	}
	return
}
开发者ID:nycmeshnet,项目名称:nodeatlas,代码行数:9,代码来源:api.go


示例10: GetStatus

// GetStatus responds with a status summary of the map, including the
// map name, total number of nodes, number available (pingable), etc.
// (Not yet implemented.)
func (*Api) GetStatus(ctx *jas.Context) {
	localNodes := Db.LenNodes(false)
	ctx.Data = map[string]interface{}{
		"Name":        Conf.Name,
		"LocalNodes":  localNodes,
		"CachedNodes": Db.LenNodes(true) - localNodes,
		"CachedMaps":  len(Conf.ChildMaps),
	}
}
开发者ID:nycmeshnet,项目名称:nodeatlas,代码行数:12,代码来源:api.go


示例11: GetNode

// GetNode retrieves a single node from the database, removes
// sensitive data (such as an email address) and sets ctx.Data to it.
func (*Api) GetNode(ctx *jas.Context) {
	ip := IP(net.ParseIP(ctx.RequireString("address")))
	if ip == nil {
		// If this is encountered, the address was incorrectly
		// formatted.
		ctx.Error = jas.NewRequestError("addressInvalid")
		return
	}
	node, err := Db.GetNode(ip)
	if err != nil {
		// If there has been a database error, log it and report the
		// failure.
		ctx.Error = jas.NewInternalError(err)
		l.Err(err)
		return
	}
	if node == nil {
		// If there are simply no matching nodes, set the error and
		// return.
		ctx.Error = jas.NewRequestError("No matching node")
		return
	}

	// Remove any sensitive data.
	node.OwnerEmail = ""

	// Finally, set the data and exit.
	ctx.Data = node
}
开发者ID:rynomad,项目名称:Nei.ghbor.Net-Keystone,代码行数:31,代码来源:api.go


示例12: GetVerify

// GetVerify moves a node from the verification queue to the normal
// database, as identified by its long random ID.
func (*Api) GetVerify(ctx *jas.Context) {
	id := ctx.RequireInt("id")
	ip, verifyerr, err := Db.VerifyQueuedNode(id, ctx.Request)
	if verifyerr != nil {
		// If there was an error inverification, there was no internal
		// error, but the circumstances of the verification were
		// incorrect. It has not been removed from the database.
		ctx.Error = jas.NewRequestError(verifyerr.Error())
		return
	} else if err == sql.ErrNoRows {
		// If we encounter a ErrNoRows, then there was no node with
		// that ID. Report it.
		ctx.Error = jas.NewRequestError("invalid id")
		l.Noticef("%q attempted to verify invalid ID\n", ctx.RemoteAddr)
		return
	} else if err != nil {
		// If we encounter any other database error, it is an internal
		// error and needs to be logged.
		ctx.Error = jas.NewInternalError(err)
		l.Err(err)
		return
	}
	// If there was no error, inform the user that it was successful,
	// and log it.
	ctx.Data = "successful"
	l.Infof("Node %q verified", ip)
}
开发者ID:nycmeshnet,项目名称:nodeatlas,代码行数:29,代码来源:api.go


示例13: PostDeleteNode

// PostDeleteNode removes a node with the given address from the
// database. This must be done from that node's address, or an admin
// address.
func (*Api) PostDeleteNode(ctx *jas.Context) {
	if Db.ReadOnly {
		// If the database is readonly, set that as the error and
		// return.
		ctx.Error = ReadOnlyError
		return
	}
	var err error

	// Require a token, because this is a very sensitive endpoint.
	RequireToken(ctx)

	// Retrieve the given IP address, check that it's sane, and check
	// that it exists in the *local* database.
	ip := IP(net.ParseIP(ctx.RequireStringLen(0, 40, "address")))
	if ip == nil {
		// If the address is invalid, return that error.
		ctx.Error = jas.NewRequestError("addressInvalid")
		return
	}

	// Check to make sure that the Node is the one sending the
	// address, or an admin. If not, return an error.
	if !net.IP(ip).Equal(net.ParseIP(ctx.RemoteAddr)) &&
		!IsAdmin(ctx.Request) {
		ctx.Error = jas.NewRequestError(
			RemoteAddressDoesNotMatchError.Error())
		return
	}

	// If all is well, then delete it.
	err = Db.DeleteNode(ip)
	if err == sql.ErrNoRows {
		// If there are no rows with that IP, explain that in the
		// error.
		//
		// I'm not actually sure this can happen. (DuoNoxSol)
		ctx.Error = jas.NewRequestError("no matching node")
	} else if err != nil {
		ctx.Error = jas.NewInternalError(err)
		l.Errf("Error deleting node: %s\n")
	} else {
		l.Infof("Node %q deleted\n", ip)
		ctx.Data = "deleted"
	}
}
开发者ID:nycmeshnet,项目名称:nodeatlas,代码行数:49,代码来源:api.go


示例14: Post

func (*Sporocilo) Post(ctx *jas.Context) {
	nick := ctx.RequireString("nick")
	msg := ctx.RequireString("msg")
	title := ctx.RequireString("title")
	if nick != "" && msg != "" {
		err, res := sporocilo.ShraniSporocilo(nick, title, msg)
		if err == nil {
			b, _ := json.Marshal(res)
			log.Println(string(b))
			Notify(string(b))
			ctx.Data = res
		}
	}
}
开发者ID:ubuntu-si,项目名称:go-ubuntusi-log,代码行数:14,代码来源:rest.go


示例15: GetNode

// GetNode retrieves a single node from the database, removes
// sensitive data (such as an email address) and sets ctx.Data to
// it. If `?geojson` is set, then it returns it in geojson.Feature
// form.
func (*Api) GetNode(ctx *jas.Context) {
	ip := IP(net.ParseIP(ctx.RequireStringLen(0, 40, "address")))
	if ip == nil {
		// If this is encountered, the address was incorrectly
		// formatted.
		ctx.Error = jas.NewRequestError("addressInvalid")
		return
	}
	node, err := Db.GetNode(ip)
	if err != nil {
		// If there has been a database error, log it and report the
		// failure.
		ctx.Error = jas.NewInternalError(err)
		l.Err(err)
		return
	}
	if node == nil {
		// If there are simply no matching nodes, set the error and
		// return.
		ctx.Error = jas.NewRequestError("No matching node")
		return
	}

	// We must invoke ParseForm() so that we can access ctx.Form.
	ctx.ParseForm()

	// If the form value 'geojson' is included, dump in GeoJSON
	// form. Otherwise, just dump with normal marhshalling.
	if _, ok := ctx.Form["geojson"]; ok {
		ctx.Data = node.Feature()
		return
	} else {
		// Only after removing any sensitive data, though.
		node.OwnerEmail = ""

		// Finally, set the data and exit.
		ctx.Data = node
	}
}
开发者ID:nycmeshnet,项目名称:nodeatlas,代码行数:43,代码来源:api.go


示例16: responseMessage

func responseMessage(resp io.Writer, ctx *jas.Context) int {
	if ctx.Error != nil {
		ctx.Status = ctx.Error.Status()
	}

	var written int
	jsonBytes, _ := json.Marshal(ctx.Data)
	if ctx.Callback != "" { // handle JSONP
		ctx.ResponseHeader.Set("Content-Type", "application/javascript; charset=utf-8")

		a, _ := resp.Write([]byte(ctx.Callback + "("))
		b, _ := resp.Write(jsonBytes)
		c, _ := resp.Write([]byte(");"))

		written = a + b + c
	} else {
		written, _ = resp.Write(jsonBytes)
	}

	return written
}
开发者ID:Altonymous,项目名称:api.6fusion.com,代码行数:21,代码来源:main.go


示例17: RequireToken

// RequireToken uses the finder to retrieve a value named "token", and
// panics with "tokenInvalid" if there is either no such value, or it
// is invalid or expired.
func RequireToken(ctx *jas.Context) {
	tokeni, err := ctx.FindInt("token")
	if err != nil || !CheckToken(ctx.RemoteAddr, uint32(tokeni)) {
		panic(jas.NewRequestError("tokenInvalid"))
	}
}
开发者ID:nycmeshnet,项目名称:nodeatlas,代码行数:9,代码来源:api.go


示例18: PostMessage

// PostMessage emails the given message to the email address owned by
// the node with the given IP. It requires a correct and non-expired
// CAPTCHA pair be given.
func (*Api) PostMessage(ctx *jas.Context) {
	// Because this is a somewhat sensitive endpoint, require a token.
	RequireToken(ctx)

	// Ensure that the given CAPTCHA pair is correct. If it is not,
	// then return the explanation. This is bypassed if the request
	// comes from an admin address.
	if !IsAdmin(ctx.Request) {
		err := VerifyCAPTCHA(ctx.Request)
		if err != nil {
			ctx.Error = jas.NewRequestError(err.Error())
			return
		}
	}

	// Next, retrieve the IP of the node the user is attempting to
	// contact.
	ip := IP(net.ParseIP(ctx.RequireStringLen(0, 40, "address")))
	if ip == nil {
		// If the address is invalid, return that error.
		ctx.Error = jas.NewRequestError("addressInvalid")
		return
	}

	// Find the appropriate variables. If any of these are not
	// found, JAS will return a request error.
	replyto := ctx.RequireStringMatch(EmailRegexp, "from")
	message := ctx.RequireStringLen(0, 1000, "message")

	// Retrieve the appropriate node from the database.
	node, err := Db.GetNode(ip)
	if err != nil {
		// If we encounter an error here, it was a database error.
		ctx.Error = jas.NewInternalError(err)
		l.Err("Error getting node %q: %s", ip, err)
		return
	} else if node == nil {
		// If the IP wasn't found, explain that there was no node with
		// that IP.
		ctx.Error = jas.NewRequestError("address unknown")
		return
	} else if len(node.OwnerEmail) == 0 {
		// If there was no email on the node, that probably means that
		// it was cached.
		ctx.Error = jas.NewRequestError("address belongs to cached node")
		return
	}

	// Create and send an email. Log any errors.
	e := &Email{
		To:      node.OwnerEmail,
		From:    Conf.SMTP.EmailAddress,
		Subject: "Message via " + Conf.Name,
	}
	e.Data = map[string]interface{}{
		"ReplyTo": replyto,
		"Message": template.HTML(message),
		"Name":    Conf.Name,
		"Link": template.HTML(Conf.Web.Hostname + Conf.Web.Prefix +
			"/node/" + ip.String()),
		"AdminContact": Conf.AdminContact,

		// Generate a random number for use as a boundary marker in the
		// multipart/alternative email.
		"Boundary": rand.Int31(),
	}

	err = e.Send("message.txt")
	if err != nil {
		ctx.Error = jas.NewInternalError(err)
		l.Errf("Error messaging %q from %q: %s",
			node.OwnerEmail, replyto, err)
		return
	}

	// Even if there is no error, log the to and from info, in case it
	// is abusive or spam.
	l.Noticef("IP %q sent a message to %q from %q",
		ctx.Request.RemoteAddr, node.OwnerEmail, replyto)
}
开发者ID:nycmeshnet,项目名称:nodeatlas,代码行数:83,代码来源:api.go


示例19: Typename

func (*Radio) Typename(ctx *jas.Context) {
	name := ctx.GapSegment("")
	ctx.Data = string(name) + "type name"
	fmt.Println(name)
}
开发者ID:jchjjj,项目名称:learnGo,代码行数:5,代码来源:example.go


示例20: GetStatus

// GetStatus responds with a status summary of the map, including the
// map name, total number of nodes, number available (pingable), etc.
// (Not yet implemented.)
func (*Api) GetStatus(ctx *jas.Context) {
	ctx.Data = apiStatus{
		Name:  Conf.Name,
		Nodes: Db.LenNodes(false),
	}
}
开发者ID:rynomad,项目名称:Nei.ghbor.Net-Keystone,代码行数:9,代码来源:api.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang qbs.GetQbs函数代码示例发布时间:2022-05-23
下一篇:
Golang assrt.Assert类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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