//curl -i -X GET 'localhost:9090/sshPort[/2200]' func (this *SshPortController) Get() { portNum := this.Ctx.Input.Params[":objectId"] 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() sshPortM := new(models.SshPortManage) //当没有传入具体的port值时,输出全部sshport对象 if portNum == "" { sshPortObs, _ := sshPortM.QueryAll(dbconn, 0) this.Data["json"] = sshPortObs this.ServeJson() this.StopRun() } //输出portNum对应的sshPort信息 sshPortOb, err := sshPortM.Query(dbconn, portNum, 0) if err != nil { logs.Error("ssh port query error:", err, 0) this.Ctx.Output.SetStatus(500) this.Ctx.Output.Body([]byte(`{"result":1,"error":"` + err.Error() + `"}`)) this.StopRun() } this.Data["json"] = sshPortOb this.ServeJson() }