Beispiel #1
0
// 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)
}
Beispiel #2
0
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
	}
}