Пример #1
0
//curl -i -X GET 'localhost:9090/sshKeys/123456/testccc?logid=4223'
func (this *SshKeysController) GetMsgByKeyname() {
	uid := this.Ctx.Input.Params[":objectId"]
	keyname := this.Ctx.Input.Params[":keyname"]
	if uid == "" || keyname == "" {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"param error"}`))
		this.StopRun()
	}

	dbconn, err := models.InitDbConn(0)
	if err != nil {
		logs.Error("db init error!", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"init db conn error"}`))
		this.StopRun()
	}
	defer dbconn.Close()

	sshKeysM := new(models.SshKeysManage)
	sshKeysOb, err := sshKeysM.Query(dbconn, uid, keyname, 0)
	if err != nil {
		logs.Error("sshkeysM getall error:", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"` + err.Error() + `"}`))
		this.StopRun()
	}
	this.Data["json"] = sshKeysOb
	this.ServeJson()
}